mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Rollup merge of #130293 - gurry:130142-lint-level-issue, r=cjgillot
Fix lint levels not getting overridden by attrs on `Stmt` nodes Fixes #130142. See comments on the issue for context. r? `@cjgillot`
This commit is contained in:
commit
18a93ca65e
@ -255,11 +255,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
|
|||||||
intravisit::walk_foreign_item(self, it);
|
intravisit::walk_foreign_item(self, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) {
|
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
|
||||||
// We will call `add_id` when we walk
|
self.add_id(s.hir_id);
|
||||||
// the `StmtKind`. The outer statement itself doesn't
|
intravisit::walk_stmt(self, s);
|
||||||
// define the lint levels.
|
|
||||||
intravisit::walk_stmt(self, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
|
||||||
|
@ -13,6 +13,14 @@ error: this lint expectation is unfulfilled
|
|||||||
LL | #[expect(invalid_nan_comparisons)]
|
LL | #[expect(invalid_nan_comparisons)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: this lint expectation is unfulfilled
|
||||||
|
--> tests/ui/expect_tool_lint_rfc_2383.rs:36:18
|
||||||
|
|
|
||||||
|
LL | #[expect(invalid_nan_comparisons)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
error: this lint expectation is unfulfilled
|
error: this lint expectation is unfulfilled
|
||||||
--> tests/ui/expect_tool_lint_rfc_2383.rs:107:14
|
--> tests/ui/expect_tool_lint_rfc_2383.rs:107:14
|
||||||
|
|
|
|
||||||
@ -37,5 +45,5 @@ error: this lint expectation is unfulfilled
|
|||||||
LL | #[expect(clippy::overly_complex_bool_expr)]
|
LL | #[expect(clippy::overly_complex_bool_expr)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
19
tests/ui/lint/lints-on-stmt-not-overridden-130142.rs
Normal file
19
tests/ui/lint/lints-on-stmt-not-overridden-130142.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Regression test for issue #130142
|
||||||
|
|
||||||
|
// Checks that we emit no warnings when a lint's level
|
||||||
|
// is overridden by an expect or allow attr on a Stmt node
|
||||||
|
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn must_use_result() -> i32 {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
#[expect(unused_must_use)]
|
||||||
|
must_use_result();
|
||||||
|
|
||||||
|
#[allow(unused_must_use)]
|
||||||
|
must_use_result();
|
||||||
|
}
|
@ -37,6 +37,8 @@ mod rustc_warn {
|
|||||||
|
|
||||||
#[expect(invalid_nan_comparisons)]
|
#[expect(invalid_nan_comparisons)]
|
||||||
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
|
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
|
||||||
|
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
|
||||||
|
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
let _b = x == 5;
|
let _b = x == 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,13 @@ warning: this lint expectation is unfulfilled
|
|||||||
LL | #[expect(invalid_nan_comparisons)]
|
LL | #[expect(invalid_nan_comparisons)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: 2 warnings emitted
|
warning: this lint expectation is unfulfilled
|
||||||
|
--> $DIR/expect_tool_lint_rfc_2383.rs:38:18
|
||||||
|
|
|
||||||
|
LL | #[expect(invalid_nan_comparisons)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
warning: 3 warnings emitted
|
||||||
|
|
||||||
|
@ -16,15 +16,22 @@
|
|||||||
pub fn normal_test_fn() {
|
pub fn normal_test_fn() {
|
||||||
#[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")]
|
#[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")]
|
||||||
//~^ WARNING this lint expectation is unfulfilled
|
//~^ WARNING this lint expectation is unfulfilled
|
||||||
|
//~| WARNING this lint expectation is unfulfilled
|
||||||
//~| NOTE this expectation will create a diagnostic with the default lint level
|
//~| NOTE this expectation will create a diagnostic with the default lint level
|
||||||
|
//~| NOTE this expectation will create a diagnostic with the default lint level
|
||||||
|
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
let mut v = vec![1, 1, 2, 3, 5];
|
let mut v = vec![1, 1, 2, 3, 5];
|
||||||
v.sort();
|
v.sort();
|
||||||
|
|
||||||
// Check that lint lists including `unfulfilled_lint_expectations` are also handled correctly
|
// Check that lint lists including `unfulfilled_lint_expectations` are also handled correctly
|
||||||
#[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
|
#[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
|
||||||
//~^ WARNING this lint expectation is unfulfilled
|
//~^ WARNING this lint expectation is unfulfilled
|
||||||
|
//~| WARNING this lint expectation is unfulfilled
|
||||||
|
//~| NOTE the expectation for `unused` should be fulfilled
|
||||||
//~| NOTE the expectation for `unused` should be fulfilled
|
//~| NOTE the expectation for `unused` should be fulfilled
|
||||||
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
||||||
|
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
||||||
|
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
let value = "I'm unused";
|
let value = "I'm unused";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,16 @@ LL | #[expect(unused_mut, reason = "this expectation will create a diagnosti
|
|||||||
= note: this expectation will create a diagnostic with the default lint level
|
= note: this expectation will create a diagnostic with the default lint level
|
||||||
|
|
||||||
warning: this lint expectation is unfulfilled
|
warning: this lint expectation is unfulfilled
|
||||||
--> $DIR/expect_unfulfilled_expectation.rs:24:22
|
--> $DIR/expect_unfulfilled_expectation.rs:17:14
|
||||||
|
|
|
||||||
|
LL | #[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")]
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this expectation will create a diagnostic with the default lint level
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
warning: this lint expectation is unfulfilled
|
||||||
|
--> $DIR/expect_unfulfilled_expectation.rs:27:22
|
||||||
|
|
|
|
||||||
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
|
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -34,5 +43,15 @@ LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectati
|
|||||||
= note: the expectation for `unused` should be fulfilled
|
= note: the expectation for `unused` should be fulfilled
|
||||||
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
||||||
|
|
||||||
warning: 4 warnings emitted
|
warning: this lint expectation is unfulfilled
|
||||||
|
--> $DIR/expect_unfulfilled_expectation.rs:27:22
|
||||||
|
|
|
||||||
|
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: the expectation for `unused` should be fulfilled
|
||||||
|
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
warning: 6 warnings emitted
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user