Skip to content

Use call_site hygiene to avoid unused qualification#7866

Merged
Darksonn merged 2 commits intotokio-rs:masterfrom
mu001999-contrib:fix/use-callsite-span
Jan 22, 2026
Merged

Use call_site hygiene to avoid unused qualification#7866
Darksonn merged 2 commits intotokio-rs:masterfrom
mu001999-contrib:fix/use-callsite-span

Conversation

@mu001999
Copy link
Copy Markdown
Contributor

@mu001999 mu001999 commented Jan 20, 2026

Motivation

Previous attempt: #7777
More context: rust-lang/rust#149873

Direct using user's span here will lead to unexpected warning of unused qualification for user code.

Solution

As @taiki-e suggests (rust-lang/rust#149873 (comment)), use Span::call_site hygiene here to help the lint can use Span::from_expansion to check it.

Have tested this solution in https://github.com/mu001999-contrib/tokio-unexpected-warning, the output is:

~/r/unexpected-warning @ main » cd base 
~/r/u/base @ main » cargo check --tests
    Checking base v0.1.0 (/Users/mu00/repos/unexpected-warning/base)
error: unnecessary qualification
 --> base/src/lib.rs:5:5
  |
5 |     if true {}
  |     ^^
  |
  = note: requested on the command line with `-D unused-qualifications`

error: could not compile `base` (lib test) due to 1 previous error
~/r/u/base @ main [101] » cd ../new          
~/r/u/new @ main » cargo check --tests
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s

The difference is that the new crate uses the dependency tokio = { git = "https://github.com/mu001999-contrib/tokio", branch = "fix/use-callsite-span", features = ["full"] }

@Darksonn Darksonn added the A-tokio-macros Area: The tokio-macros crate label Jan 20, 2026
@mu001999 mu001999 force-pushed the fix/use-callsite-span branch 2 times, most recently from 3cea2f7 to 85ae3ea Compare January 21, 2026 01:07
@Darksonn
Copy link
Copy Markdown
Member

It sounds like the output is still incorrect. Am I mistaken? What is the output prior to this change?

@mu001999
Copy link
Copy Markdown
Contributor Author

It sounds like the output is still incorrect. Am I mistaken? What is the output prior to this change?

The above output have two parts, base is the output prior to this change:

~/r/unexpected-warning @ main » cd base 
~/r/u/base @ main » cargo check --tests
    Checking base v0.1.0 (/Users/mu00/repos/unexpected-warning/base)
error: unnecessary qualification
 --> base/src/lib.rs:5:5
  |
5 |     if true {}
  |     ^^
  |
  = note: requested on the command line with `-D unused-qualifications`

error: could not compile `base` (lib test) due to 1 previous error

The new is the output after this change:

~/r/u/base @ main [101] » cd ../new          
~/r/u/new @ main » cargo check --tests
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s

@Darksonn
Copy link
Copy Markdown
Member

Ah, so the error went away. That's great. Could we test this under tests-build?

@mu001999
Copy link
Copy Markdown
Contributor Author

Could we test this under tests-build?

Yes, I have added one.

@mu001999 mu001999 force-pushed the fix/use-callsite-span branch from 85ae3ea to a2c7801 Compare January 21, 2026 14:44
@mu001999 mu001999 requested a review from Darksonn January 21, 2026 14:50
Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

It looks ok to me, but I'd like to hear from @taiki-e too.

@Darksonn Darksonn requested a review from taiki-e January 21, 2026 14:52
@Darksonn Darksonn merged commit 63abec0 into tokio-rs:master Jan 22, 2026
88 checks passed
@mu001999 mu001999 deleted the fix/use-callsite-span branch January 22, 2026 15:27
@djc
Copy link
Copy Markdown
Contributor

djc commented Jan 22, 2026

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio-macros Area: The tokio-macros crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants