Skip to content

Let dead_code lint work on #[instrument]ed functions #3108

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

Merged
merged 1 commit into from
May 30, 2025

Conversation

9999years
Copy link
Contributor

@9999years 9999years commented Oct 17, 2024

Motivation

#[instrument]ed functions never trigger a dead_code lint.

Closes (partially?) #1366

Solution

Include all of the input tokens in the output. In particular, the brace tokens surrounding the function body, the parenthesis surrounding the function parameters, and the angle brackets surrounding the generics must be included.

Prior art: andrewhickman/fn-error-context@cfa749a

@9999years 9999years requested review from hawkw, davidbarsky and a team as code owners October 17, 2024 02:22
@9999years 9999years force-pushed the fix-dead-code branch 3 times, most recently from b1af999 to 0928c37 Compare October 17, 2024 02:33
@9999years 9999years changed the title Let dead_code lint work on #[instrumented functions Let dead_code lint work on #[instrument]ed functions Oct 21, 2024
@9999years 9999years force-pushed the fix-dead-code branch 2 times, most recently from 5c58b47 to cb4d357 Compare October 22, 2024 18:41
Copy link
Member

@jplatte jplatte left a comment

Choose a reason for hiding this comment

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

I love it! Could you rebase?

@@ -72,6 +72,7 @@ async fn main() -> Result<(), Err> {
let svc = Server::bind(&addr).serve(svc);
let admin = Server::bind(&admin_addr).serve(admin);

#[allow(clippy::incompatible_msrv)]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this won't be needed anymore after rebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks OK to remove on my machine, let's see about CI...

@@ -10,7 +10,6 @@ async fn simple_mismatch() -> String {
""
}

// FIXME: this span is still pretty poor
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, removing this comment moved all the error locations...

| |_^ expected `i32`, found `()`
--> tests/ui/async_instrument.rs:40:1
|
40 | #[tracing::instrument]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This span is a little worse now, unfortunately. Not sure what's up with that.

@9999years
Copy link
Contributor Author

@jplatte Rebased, PTAL!

@jplatte jplatte enabled auto-merge (squash) May 30, 2025 09:21
@jplatte jplatte disabled auto-merge May 30, 2025 09:21
@jplatte jplatte enabled auto-merge (squash) May 30, 2025 09:21
@jplatte jplatte merged commit 1619fa8 into tokio-rs:master May 30, 2025
56 checks passed
@jplatte jplatte mentioned this pull request May 30, 2025
25 tasks
hds pushed a commit that referenced this pull request Jun 2, 2025
hds pushed a commit that referenced this pull request Jun 3, 2025
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 10, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths (#3126)

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 10, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths ([#3126])

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 10, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths ([#3126])

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126

Signed-off-by: Hayden Stainsby <[email protected]>
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 10, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths ([#3126])

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126

Signed-off-by: Hayden Stainsby <[email protected]>
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 6, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths ([#3126])

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126
hds added a commit that referenced this pull request Jun 6, 2025
# 0.1.29 (June 6, 2025)

### Changed

- Bump MSRV to 1.65 ([#3033])

### Fixed

- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108])
- Globally qualify attribute paths ([#3126])

[#3033]: #3033
[#3108]: #3108
[#3126]: #3126
@grahamc
Copy link

grahamc commented Jun 12, 2025

Looks like this closed #3207 too

@jplatte
Copy link
Member

jplatte commented Jun 12, 2025

Great! Now we just need to fix the regression caused by this 😅 (see #3306)

@grahamc

This comment was marked as resolved.

@jplatte
Copy link
Member

jplatte commented Jun 12, 2025

Yes, please! I suspect that one is probably a lot harder to fix, I have a PR up for the first regression now.

hds pushed a commit that referenced this pull request Jun 13, 2025
The change to allow the `dead_code` lint to work on the
`#[instrument]` attribute (#3108) introduced a shadowing
problem which caused compilation failure in certain cases,
as reported in #3306.

The body of the original function was not given its own scope
and `use` statements made there could leak out into the
code inserted by the `#[instrument]`.

This change fixes this problem by explicitly re-introducing the
parenthesis to give the original function body its own scope.

Closes #3306
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