Skip to content

fix: unfulfilled nested dead code lint - #161005

Open
dronavallipranav wants to merge 1 commit into
rust-lang:mainfrom
dronavallipranav:fix-nested-dead-code-expectations
Open

fix: unfulfilled nested dead code lint#161005
dronavallipranav wants to merge 1 commit into
rust-lang:mainfrom
dronavallipranav:fix-nested-dead-code-expectations

Conversation

@dronavallipranav

@dronavallipranav dronavallipranav commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #160942

Dead code diagnostic being covered by parent's dead diagnostic resulting in false positives on expectations not being fulfilled. fixed by checking each child of a dead item for its own expectation now and fulfilling their expectation (if valid). Follows suite for manually fulfilling expect level diagnostics (copies mechanism from LintContext::fulfill_expectation.

UI tests fail as expected on main (without fix)

Input

// This struct is only used on windows.
#[cfg_attr(not(target_os = "windows"), expect(unused))]
struct Foo {
    // This field is never used regardless of whether on windows or other.
    #[expect(unused)]
    x: u32,
}

Output
Before

warning: this lint expectation is unfulfilled
 --> src/lib.rs:5:14
  |
5 |     #[expect(unused)]
  |              ^^^^^^

After: no output

I used llm originally to get an understanding of the existing flows and context of the flow around the problem, through prompting helped locate how could reuse the dummy diagnostic lint strategy created cases and I worked backwards from these cases to generate implementation and corresponding logic. I then had it wrote UI tests for those cases for me. The UI tests felt redundant to recreate since I already had it generate the original cases the linter was meant to handle and after review they seem robust couldn't seem to come up with another case.

 expectations not fulfulling
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 12, 2026
@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 17 candidates

@folkertdev

Copy link
Copy Markdown
Contributor

r? JonathanBrouwer because lints?

I'm not sure we even want this though, it probably needs T-lang approval, or input at least

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unfulfilled_lint_expectations false-positive for unused struct field inside unused struct

4 participants