-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix span in proc macro #4265
base: master
Are you sure you want to change the base?
Fix span in proc macro #4265
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR 🙏
The changes itself look fine to me, although I personally would prefer to address all potential other locations that somewhat use a span at once.
(Also as minor note: Would it be possible to squash all those commits?)
@@ -93,7 +93,8 @@ where | |||
} | |||
|
|||
pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream { | |||
// #[allow(unused_qualifications)] can be removed if https://github.com/rust-lang/rust/issues/130277 gets done | |||
// allow(unused_qualifications) is here as it hard to unsure the span is correctly set. Should stay until it is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather prefer auditing the derive crate to ensure all usages of spans are encoded correctly. Yes that's a bit of work but it should fix all these issues at once.
The alternative is to remove this allow and start searching again if something pops up in some code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a lot of work for something that's seldom going to be noticed considering the warning is not enabled by default. It looks like it's going to be hard to maintain if we don't have it in our CI.
To make that practical to fix and maintain, it looks like syn
's Spanned
trait should have a span_mixed
method that constructs this.
Follow up of rust-lang/rust#130277 that was initially handled in #4259. The rust team pointed out that the macro was not correctly setting the span and proposed a fix, being the use of Span::mixed_site instead of coping directly the span of the field.
The #[allow(unused_qualifications)] is still here in the wrap_in_dummy_mod as it is hard to make sure the lint is correctly done in every proc macro.