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

Fix span in proc macro #4265

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

Sindbad-Walter
Copy link
Contributor

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.

@weiznich weiznich requested a review from a team September 16, 2024 12:47
@Sindbad-Walter Sindbad-Walter marked this pull request as draft September 16, 2024 12:55
@Sindbad-Walter Sindbad-Walter marked this pull request as ready for review September 17, 2024 12:36
Copy link
Member

@weiznich weiznich left a 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
Copy link
Member

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants