-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #114710 - Urgau:fix-expect-dead_code-114557, r=cjgillot
Respect `#[expect]` the same way `#[allow]` is with the `dead_code` lint This PR makes the `#[expect]` attribute being respected in the same way the `#[allow]` attribute is with the `dead_code` lint. The fix is much more involved than I would have liked (and it's not because I didn't tried!), because the implementation took advantage of the fact that firing a lint in a allow context is a nop (for the user, as the lint is suppressed) to not fire-it at all. And will it's fine for `#[allow]`, it definitively isn't for `#[expect]`, as the presence and absence of the lint is significant. So a big part of the PR is just adding the context information of whenever an item is on the worklist because of an `[allow]`/`#[expect]` or not. Fixes #114557
- Loading branch information
Showing
6 changed files
with
163 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
tests/ui/lint/dead-code/allow-or-expect-dead_code-114557-2.rs
This file contains 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,19 @@ | ||
// check-pass | ||
|
||
// this test checks that the `dead_code` lint is *NOT* being emited | ||
// for `foo` as `foo` is being used by `main`, and so the `#[expect]` | ||
// is unfulfilled | ||
// | ||
// it also checks that the `dead_code` lint is also *NOT* emited | ||
// for `bar` as it's suppresed by the `#[expect]` on `bar` | ||
|
||
#![feature(lint_reasons)] | ||
#![warn(dead_code)] // to override compiletest | ||
|
||
fn bar() {} | ||
|
||
#[expect(dead_code)] | ||
//~^ WARN this lint expectation is unfulfilled | ||
fn foo() { bar() } | ||
|
||
fn main() { foo() } |
10 changes: 10 additions & 0 deletions
10
tests/ui/lint/dead-code/allow-or-expect-dead_code-114557-2.stderr
This file contains 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/allow-or-expect-dead_code-114557-2.rs:15:10 | ||
| | ||
LL | #[expect(dead_code)] | ||
| ^^^^^^^^^ | ||
| | ||
= note: `#[warn(unfulfilled_lint_expectations)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
13 changes: 13 additions & 0 deletions
13
tests/ui/lint/dead-code/allow-or-expect-dead_code-114557-3.rs
This file contains 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,13 @@ | ||
// check-pass | ||
|
||
// this test makes sure that the `unfulfilled_lint_expectations` lint | ||
// is being emited for `foo` as foo is not dead code, it's pub | ||
|
||
#![feature(lint_reasons)] | ||
#![warn(dead_code)] // to override compiletest | ||
|
||
#[expect(dead_code)] | ||
//~^ WARN this lint expectation is unfulfilled | ||
pub fn foo() {} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
tests/ui/lint/dead-code/allow-or-expect-dead_code-114557-3.stderr
This file contains 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/allow-or-expect-dead_code-114557-3.rs:9:10 | ||
| | ||
LL | #[expect(dead_code)] | ||
| ^^^^^^^^^ | ||
| | ||
= note: `#[warn(unfulfilled_lint_expectations)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lint/dead-code/allow-or-expect-dead_code-114557.rs
This file contains 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,18 @@ | ||
// check-pass | ||
// revisions: allow expect | ||
|
||
// this test checks that no matter if we put #[allow(dead_code)] | ||
// or #[expect(dead_code)], no warning is being emited | ||
|
||
#![feature(lint_reasons)] | ||
#![warn(dead_code)] // to override compiletest | ||
|
||
fn f() {} | ||
|
||
#[cfg_attr(allow, allow(dead_code))] | ||
#[cfg_attr(expect, expect(dead_code))] | ||
fn g() { | ||
f(); | ||
} | ||
|
||
fn main() {} |