Repository navigation
fix: unfulfilled nested dead code lint #161005
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
rust-bors
merged 1 commit into
rust-lang:main
from
dronavallipranav:fix-nested-dead-code-expectations
Sep 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/ui/lint/rfc-2383-lint-reason/expect_inside_dead_code.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| //@ check-pass | ||
| // Expectations on dead code covered by a dead parent's diagnostic must still be fulfilled. | ||
|
|
||
| #[cfg_attr(all(), expect(unused))] | ||
| struct Foo { | ||
| #[expect(unused)] | ||
| x: u32, | ||
| } | ||
|
|
||
| #[expect(dead_code)] | ||
| struct Direct { | ||
| #[expect(dead_code)] | ||
| x: u32, | ||
| } | ||
|
|
||
| #[expect(unused)] | ||
| enum DeadEnum { | ||
| Variant { | ||
| #[expect(unused)] | ||
| x: u32, | ||
| }, | ||
| } | ||
|
|
||
| enum PartiallyDead { | ||
| Used, | ||
| #[expect(unused)] | ||
| Dead { | ||
| #[expect(unused)] | ||
| x: u32, | ||
| }, | ||
| } | ||
|
|
||
| #[expect(unused)] | ||
| fn dead_outer() { | ||
| #[expect(unused)] | ||
| fn dead_inner() {} | ||
| } | ||
|
|
||
| #[expect(unused)] | ||
| trait DeadTrait { | ||
| #[expect(unused)] | ||
| fn dead_method(&self); | ||
| } | ||
|
|
||
| // `y` is read, so this expectation must stay unfulfilled. | ||
| struct Live { | ||
| #[expect(unused)] | ||
| //~^ WARNING this lint expectation is unfulfilled | ||
| //~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default | ||
| y: u32, | ||
| } | ||
|
|
||
| fn main() { | ||
| let _ = PartiallyDead::Used; | ||
| let _ = Live { y: 1 }.y; | ||
| } |
10 changes: 10 additions & 0 deletions
10
tests/ui/lint/rfc-2383-lint-reason/expect_inside_dead_code.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| warning: this lint expectation is unfulfilled | ||
| --> $DIR/expect_inside_dead_code.rs:47:14 | ||
| | | ||
| LL | #[expect(unused)] | ||
| | ^^^^^^ | ||
| | | ||
| = note: `#[warn(unfulfilled_lint_expectations)]` on by default | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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'm not a fan of the amount of special-casing needed here (and afraid we missed something) but this seems to be an existing issue of how the dead code lint works, starting from free items, and not something that is worsened significantly by this PR
View changes since the review