You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive warning on if keyword for unused_qualifications #149873
This is related to setting span in proc macros. I think there may be more potential issues, not just related to unused_qualifications. I will provide a brief summary and possible solutions when I am free.
SO I think this position is expected in fact. The first we can do to fix this may be using ::tokio::runtime in the implementation of #[tokio::test].
🤔 And furthermore, considering the flexibility of proc-macro, we can even set empty spans if we want, which may lead to ICEs. And we even cannot tell such spans are from proc-macro or not (IIRC).
SO I think this position is expected in fact. The first we can do is to fix this may be using ::tokio::runtime in the implementation of #[tokio::test].
Did you actually try whether that helps? It doesn't seem obvious that it would...
This looks like it's basically exactly the same root issue as #122519 (and that also has some of the same discussion around proc macro using input spans in the output making it impossible to tell for the lint that this comes from a macro). #122435 changed the lint to not lint on absolute paths, so changing it to ::tokio::runtime sounds like it should indeed fix that. It also looks like a mistake to me that all paths are absolute except for that one in the return statement.
And we even cannot tell such spans are from proc-macro or not (IIRC).
cc #130995, we've had this issue for a long time in Clippy and have some hacks to deal with this, but it would be very nice if there was a general solution to this problem
I'm pretty sure many other lints have logic to not trigger on macro generated code. Can't we use the same logic? Or is the issue Tokio is emitting the wrong span to trigger that logic?
I'm going to close this because there is no action needed in rustc. The lint already does not trigger on macro-generated code when the right span is present.
Activity
mu001999 commentedon Dec 11, 2025
djc commentedon Dec 11, 2025
Can you try against the branch from this PR (after removing the suppression)?
mu001999 commentedon Dec 12, 2025
@djc It has been merged, could you provide a specific commit which can reproduce this directly?
djc commentedon Dec 12, 2025
Here's how I can reproduce it:
mu001999 commentedon Dec 12, 2025
@djc Thanks! I reproduced it. I will take a look.
@rustbot claim
mu001999 commentedon Dec 12, 2025
MCVE:
And we will get:
mu001999 commentedon Dec 12, 2025
This is related to setting span in proc macros. I think there may be more potential issues, not just related to unused_qualifications. I will provide a brief summary and possible solutions when I am free.
mu001999 commentedon Dec 15, 2025
For this issue, it's because
#[tokio::test]will expand the input into things like (using the above example in #149873 (comment)):So when we have
use tokio::runtime;outer, we will get the warning for unused_qualifications.But
#[tokio::test]will use thespanof the last stmt for the generated stmt, see see https://github.com/tokio-rs/tokio/blob/master/tokio-macros/src/entry.rs#L395-L422. That's why we will get the warning reported onif.SO I think this position is expected in fact. The first we can do to fix this may be using
::tokio::runtimein the implementation of#[tokio::test].🤔 And furthermore, considering the flexibility of proc-macro, we can even set empty spans if we want, which may lead to ICEs. And we even cannot tell such spans are from proc-macro or not (IIRC).
djc commentedon Dec 15, 2025
Did you actually try whether that helps? It doesn't seem obvious that it would...
y21 commentedon Dec 15, 2025
This looks like it's basically exactly the same root issue as #122519 (and that also has some of the same discussion around proc macro using input spans in the output making it impossible to tell for the lint that this comes from a macro). #122435 changed the lint to not lint on absolute paths, so changing it to
::tokio::runtimesounds like it should indeed fix that. It also looks like a mistake to me that all paths are absolute except for that one in the return statement.cc #130995, we've had this issue for a long time in Clippy and have some hacks to deal with this, but it would be very nice if there was a general solution to this problem
Darksonn commentedon Jan 12, 2026
Changing the macro to emit
::tokio::runtimeis a breaking change.IMO this warning should not be emitted on macro generated code in the first place.
mu001999 commentedon Jan 12, 2026
Unfortunately, this span is the first span of the last statement. We cannot know the code is macro generated in current implementation.
But I think we can check the code at the span is same to the path segment or not, and don't emit if this is not. I can try this later.
Darksonn commentedon Jan 12, 2026
I'm pretty sure many other lints have logic to not trigger on macro generated code. Can't we use the same logic? Or is the issue Tokio is emitting the wrong span to trigger that logic?
mu001999 commentedon Jan 12, 2026
@Darksonn Yes, we used
Span::from_expansionto check normal macro generated code.But for
proc_macrowhich calls things likequote_spanned!(for tokio, it's https://github.com/tokio-rs/tokio/blob/master/tokio-macros/src/entry.rs#L395-L422), it will forward users span directly, andSpan::from_expansionwill returnfalse.You can see more analysis in #130995.
Darksonn commentedon Jan 12, 2026
It was changed to use
quote_spanned!in tokio-rs/tokio#3766. @taiki-e do you have any input?taiki-e commentedon Jan 12, 2026
Maybe using
Span::call_site().located_at(span)instead ofspaninquote_spanned(like taiki-e/pin-project@5a1a568) resolves the issue.mu001999 commentedon Jan 22, 2026
Has been fixed in tokio-rs/tokio#7866
Darksonn commentedon Jan 22, 2026
I'm going to close this because there is no action needed in rustc. The lint already does not trigger on macro-generated code when the right span is present.