fix: unfulfilled nested dead code lint - #161005
dronavallipranav wants to merge 1 commit into
Conversation
expectations not fulfulling
|
r? @folkertdev rustbot has assigned @folkertdev. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? JonathanBrouwer because lints? I'm not sure we even want this though, it probably needs T-lang approval, or input at least |
|
I feel a bit iffy about whether the original issue is really an issue, so I'll let the lang team decide. struct Foo {
#[expect(unused)]
x: u32,
}Currently this example produces the following output This is because if This is implemented by recursively matching expectations of specifically the dead-code lint on children of dead items. Having such a special case for the On the other hand, this does unlock the usecase from the original issue where @rust-lang/lang @rust-lang/lang-advisors |
|
Some observations: we don't allow this, today: #![deny(unfulfilled_lint_expectations)]
#[expect(unused)]
struct Root {
#[expect(unused)] // ERROR: this lint expectation is unfulfilled
leaf: u8,
}And we don't allow: #![deny(unfulfilled_lint_expectations)]
#[expect(dead_code)]
fn root() {
#[expect(dead_code)] // ERROR: this lint expectation is unfulfilled
fn leaf() {}
leaf()
}But we do allow this: #![deny(unfulfilled_lint_expectations)]
#[expect(dead_code)]
fn root() { leaf() }
#[expect(dead_code)]
fn leaf() {} // OK. |
|
Unless it already exists somewhere else, I think we'd want to also have/add the test case @JonathanBrouwer mentioned of struct Foo {
#[expect(unused)]
x: u32,
}to the test suite, where |
|
We talked about this in the lang call today. On the call, our expectation was that all three of the examples in #161005 (comment) should be accepted (i.e., the expectation fulfilled), in principle. That's what we'd document as the intended behavior in the Reference. That said, we're cognizant of possible performance implications, and we leave to compiler the question of whether or when to implement this intended semantic on performance grounds. @rfcbot fcp merge lang |
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
@rfcbot reviewed |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…tions, r=<try> fix: unfulfilled nested dead code lint
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (4169f58): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesResults (primary -0.3%, secondary -3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 476.065s -> 473.967s (-0.44%) |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
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
Output
Before
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.