Skip to content

Commit bea0e64

Browse files
committed
Fix lint levels not getting overridden by attrs on Stmt nodes
1 parent 712463d commit bea0e64

10 files changed

+145
-9
lines changed

compiler/rustc_lint/src/levels.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
255255
intravisit::walk_foreign_item(self, it);
256256
}
257257

258-
fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) {
259-
// We will call `add_id` when we walk
260-
// the `StmtKind`. The outer statement itself doesn't
261-
// define the lint levels.
262-
intravisit::walk_stmt(self, e);
258+
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
259+
self.add_id(s.hir_id);
260+
intravisit::walk_stmt(self, s);
263261
}
264262

265263
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {

tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect-future_breakage-crash-issue-126521.rs:30:14
3+
|
4+
LL | #[expect(semicolon_in_expressions_from_macros)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
9+
warning: this lint expectation is unfulfilled
10+
--> $DIR/expect-future_breakage-crash-issue-126521.rs:33:14
11+
|
12+
LL | #[expect(semicolon_in_expressions_from_macros)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
warning: 2 warnings emitted
16+
117
Future incompatibility report: Future breakage diagnostic:
218
warning: trailing semicolon in macro used in expression position
319
--> $DIR/expect-future_breakage-crash-issue-126521.rs:7:13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for issue #130142
2+
3+
// Checks that we emit no warnings when a lint's level
4+
// is overridden by an expect or allow attr on a Stmt node
5+
6+
//@ check-pass
7+
8+
#[must_use]
9+
pub fn must_use_result() -> i32 {
10+
42
11+
}
12+
13+
fn main() {
14+
#[expect(unused_must_use)]
15+
must_use_result();
16+
17+
#[allow(unused_must_use)]
18+
must_use_result();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/lints-on-stmt-not-overridden-130142.rs:14:14
3+
|
4+
LL | #[expect(unused_must_use)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
9+
warning: 1 warning emitted
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect_inside_macro.rs:7:18
3+
|
4+
LL | #[expect(unused_variables)]
5+
| ^^^^^^^^^^^^^^^^
6+
...
7+
LL | expect_inside_macro!();
8+
| ---------------------- in this macro invocation
9+
|
10+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
11+
= note: this warning originates in the macro `expect_inside_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
warning: 1 warning emitted
14+
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect_tool_lint_rfc_2383.rs:24:18
3+
|
4+
LL | #[expect(invalid_nan_comparisons)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
19
warning: this lint expectation is unfulfilled
210
--> $DIR/expect_tool_lint_rfc_2383.rs:32:14
311
|
412
LL | #[expect(dead_code)]
513
| ^^^^^^^^^
14+
15+
warning: this lint expectation is unfulfilled
16+
--> $DIR/expect_tool_lint_rfc_2383.rs:38:18
617
|
7-
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
18+
LL | #[expect(invalid_nan_comparisons)]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^
820

921
warning: this lint expectation is unfulfilled
1022
--> $DIR/expect_tool_lint_rfc_2383.rs:38:18
1123
|
1224
LL | #[expect(invalid_nan_comparisons)]
1325
| ^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1428

15-
warning: 2 warnings emitted
29+
warning: 4 warnings emitted
1630

tests/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr

+28-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ LL | #[expect(unused_mut, reason = "this expectation will create a diagnosti
2525
|
2626
= note: this expectation will create a diagnostic with the default lint level
2727

28+
warning: this lint expectation is unfulfilled
29+
--> $DIR/expect_unfulfilled_expectation.rs:17:14
30+
|
31+
LL | #[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")]
32+
| ^^^^^^^^^^
33+
|
34+
= note: this expectation will create a diagnostic with the default lint level
35+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
36+
37+
warning: this lint expectation is unfulfilled
38+
--> $DIR/expect_unfulfilled_expectation.rs:24:14
39+
|
40+
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
41+
| ^^^^^^
42+
|
43+
= note: the expectation for `unused` should be fulfilled
44+
45+
warning: this lint expectation is unfulfilled
46+
--> $DIR/expect_unfulfilled_expectation.rs:24:22
47+
|
48+
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
|
51+
= note: the expectation for `unused` should be fulfilled
52+
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
53+
2854
warning: this lint expectation is unfulfilled
2955
--> $DIR/expect_unfulfilled_expectation.rs:24:22
3056
|
@@ -33,6 +59,7 @@ LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectati
3359
|
3460
= note: the expectation for `unused` should be fulfilled
3561
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
62+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3663

37-
warning: 4 warnings emitted
64+
warning: 7 warnings emitted
3865

tests/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,13 @@ LL | while true {
3636
|
3737
= note: requested on the command line with `--force-warn while-true`
3838

39-
warning: 5 warnings emitted
39+
warning: this lint expectation is unfulfilled
40+
--> $DIR/force_warn_expected_lints_fulfilled.rs:40:14
41+
|
42+
LL | #[expect(unused_variables)]
43+
| ^^^^^^^^^^^^^^^^
44+
|
45+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
46+
47+
warning: 6 warnings emitted
4048

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/fulfilled_expectation_early_lints.rs:4:14
3+
|
4+
LL | #[expect(while_true)]
5+
| ^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
9+
warning: this lint expectation is unfulfilled
10+
--> $DIR/fulfilled_expectation_early_lints.rs:9:14
11+
|
12+
LL | #[expect(unused_doc_comments)]
13+
| ^^^^^^^^^^^^^^^^^^^
14+
15+
warning: 2 warnings emitted
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/fulfilled_expectation_late_lints.rs:26:22
3+
|
4+
LL | #[expect(unused_variables)]
5+
| ^^^^^^^^^^^^^^^^
6+
...
7+
LL | expect_inside_macro!();
8+
| ---------------------- in this macro invocation
9+
|
10+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
11+
= note: this warning originates in the macro `expect_inside_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)