Skip to content

Comments

Improve stepper structs a bit#224

Open
vswarte wants to merge 7 commits intomainfrom
feat/er-steppers
Open

Improve stepper structs a bit#224
vswarte wants to merge 7 commits intomainfrom
feat/er-steppers

Conversation

@vswarte
Copy link
Owner

@vswarte vswarte commented Feb 13, 2026

No description provided.

/// The implementer must ensure that the enum discriminants have no gaps. Failing to do so will
/// allow out of bounds access to the stepper array as well as cause unknown discriminants.
#[proc_macro_derive(StepperStates)]
pub fn derive_stepper_states(input: TokenStream) -> TokenStream {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cool idea and I like the direction, but I think some improvements can be made in terms of safety:

  • Require concrete stepper types to implement an unsafe trait that states their step array size. There's no unsafe derive macros, so currently there's a soundness hole (even if the comment states the invariants).
  • Check for discriminator gaps.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the expectation that implementing an unsafe trait even through a derive macro is sound as long as the safety requirements are followed? Not to say I'm not looking forward to derive(unsafe(...)) but I don't think the current state is UB (otherwise I think defining a derive macro for an unsafe trait at all would be an error).

Copy link
Owner Author

@vswarte vswarte Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dasaav-dsv I think this is a soundness issue the same way implementing FromStatic using a macro would be. I'd rather just add the discriminator gap validation and laugh at people fucking up their enum in deranged ways

@vswarte vswarte changed the title Improve stepper structs a bit [Shared][ER] Improve stepper structs a bit Feb 16, 2026
@vswarte vswarte changed the title [Shared][ER] Improve stepper structs a bit \Improve stepper structs a bit Feb 16, 2026
@vswarte vswarte changed the title \Improve stepper structs a bit Improve stepper structs a bit Feb 16, 2026
@vswarte vswarte requested a review from Dasaav-dsv February 20, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants