-
Notifications
You must be signed in to change notification settings - Fork 152
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
Use proper span when generating matches
token
#398
Conversation
In `struct-opt-derive`, a function is generated with a parameter named `matches`. Since `quote!` is used to generate the function, the `matches` token will be resolved using `Span::call_site`. However, the literal identifier `matches` is also used inside several `quote_spanned!` expressions. Such a `matches` identifier will be resolved using the `Span` passed to `quote_spanned!`, which may not be the same as `Span::call_site`. Currently, this is difficult to observe in practice, due to rust-lang/rust#43081 . However, once PR rust-lang/rust#73084 is merged, proc macros will see properly spanned tokens in more cases, which will cause these incorrect uses of `quote_spanned!` to break. This PR uses `quote! { matches }` to generate a correctly spanned `matches` token, which is then include in the `quote_spanned!` expressions using `#matches`.
The test failures seem unrelated to this PR. |
This issue is pretty interesting. I recall I had noticed this problem and been thinking about for a while it but eventually came to conclusion that since What I didn't notice is that the match is located inside a cycle ( @Aaron1011 Could you please factor the |
Merged in #400 |
@CreepySkeleton: Thanks! Would it be possible for you to make a new point release? This will prevent rust-lang/rust#73084 from causing regressiosn when it lands? |
Sure. I'm working on another bugfix ATM and I will either finish in a day or two and make one release for the both (just so we have something meaningful to put in changelog) or give up and make a release all the same. Is that fine or you need it ASAP? |
@CreepySkeleton: That's fine by me - the Rust PR will be merged in a couple days at the absolute earliest, since it's waiting on a Crater run. |
Released in |
In
struct-opt-derive
, a function is generated with a parameter namedmatches
. Sincequote!
is used to generate the function, thematches
token will be resolved usingSpan::call_site
.However, the literal identifier
matches
is also used inside severalquote_spanned!
expressions. Such amatches
identifier will beresolved using the
Span
passed toquote_spanned!
, which may not bethe same as
Span::call_site
.Currently, this is difficult to observe in practice, due to
rust-lang/rust#43081 . However, once PR rust-lang/rust#73084
is merged, proc macros will see properly spanned tokens in more cases,
which will cause these incorrect uses of
quote_spanned!
to break.This PR uses
quote! { matches }
to generate a correctly spannedmatches
token, which is then include in thequote_spanned!
expressions using
#matches
.