Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust enum variant spans to exclude any explicit discriminant #5687

Merged
merged 1 commit into from Jun 19, 2023

Conversation

ytmimi
Copy link
Contributor

@ytmimi ytmimi commented Feb 8, 2023

Fixes #5686

For reference, explicit discriminants were proposed in RFC-2363, and I believe the feature is stabilized.

ast::Variant spans extend to include explicit discriminants when they are present.

Now we'll adjust the span of enum variants to exclude any explicit discriminant.

@calebcartwright
Copy link
Member

Would suggest including the search needle in a few other pathological positions, e.g. within a comment or an attribute (assuming the latter is at least parseable, even if invalid syntactically), to make sure that span_after will suffice vs. something more positionally explicit span_after_last

@ytmimi
Copy link
Contributor Author

ytmimi commented Mar 13, 2023

Just want to make sure I'm understanding you correctly. Are you referring to a scenario like this:

enum Animal {
    // Closing tuple struct needle --------|
    //                                     v
    Dog(/* Coment with closing parenthesis ) */) = 1,
    Cat(/* Coment with */ #[hello(world)] String) = 2,
    //                                 ^
    // Closing tuple struct needle ----|

}

@calebcartwright
Copy link
Member

Just want to make sure I'm understanding you correctly. Are you referring to a scenario like this:

enum Animal {
    // Closing tuple struct needle --------|
    //                                     v
    Dog(/* Coment with closing parenthesis ) */) = 1,
    Cat(/* Coment with */ #[hello(world)] String) = 2,
    //                                 ^
    // Closing tuple struct needle ----|

}

Yup exactly, anywhere some sneaky needles could reside in a parseable position

@ytmimi ytmimi force-pushed the issue_5686 branch 2 times, most recently from e0f9ec9 to 04623fb Compare March 25, 2023 01:41
Fixes 5686

For reference, explicit discriminants were proposed in [RFC-2363].

`ast::Variant` spans extend to include explicit discriminants when they
are present.

Now we'll adjust the span of enum variants to exclude any explicit
discriminant.

[RFC-2363]: https://rust-lang.github.io/rfcs/2363-arbitrary-enum-discriminant.html
@ytmimi
Copy link
Contributor Author

ytmimi commented Mar 25, 2023

@calebcartwright I made some updates to the PR. A combination of shrinking the variant.span to exclude the discriminant, before using span_after_last to pinpoint the end of the variant. I decided to move the span calculation to its own function since I think we'll be able to reuse it when fixing #5713

Fox(/* tuple variant closer on const fn call */) = some_const_fn(),
Ant(/* tuple variant closer on macro call */) = some_macro!(),
Snake {/* stuct variant closer in comment -> } */} = 6,
#[hell{world}]
Copy link
Member

Choose a reason for hiding this comment

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

lol 🔥

@calebcartwright calebcartwright added release-notes Needs an associated changelog entry and removed pr-not-reviewed labels Jun 19, 2023
@calebcartwright calebcartwright merged commit 2c30fa5 into rust-lang:master Jun 19, 2023
27 checks passed
@ytmimi ytmimi deleted the issue_5686 branch June 19, 2023 19:05
@calebcartwright calebcartwright removed the release-notes Needs an associated changelog entry label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants