Unspecified,
}
-/// Each lint expectation has a `LintExpectationId` assigned by the
-/// [`LintLevelsBuilder`][`rustc_lint::levels::LintLevelsBuilder`]. Expected
-/// [`Diagnostic`][`rustc_errors::Diagnostic`]s get the lint level `Expect` which
-/// stores the `LintExpectationId` to match it with the actual expectation later on.
+/// Each lint expectation has a `LintExpectationId` assigned by the `LintLevelsBuilder`.
+/// Expected `Diagnostic`s get the lint level `Expect` which stores the `LintExpectationId`
+/// to match it with the actual expectation later on.
///
/// The `LintExpectationId` has to be has stable between compilations, as diagnostic
/// instances might be loaded from cache. Lint messages can be emitted during an
/// HIR tree. The AST doesn't have enough information to create a stable id. The
/// `LintExpectationId` will instead store the [`AttrId`] defining the expectation.
/// These `LintExpectationId` will be updated to use the stable [`HirId`] once the
-/// AST has been lowered. The transformation is done by the
-/// [`LintLevelsBuilder`][`rustc_lint::levels::LintLevelsBuilder`]
+/// AST has been lowered. The transformation is done by the `LintLevelsBuilder`
///
/// Each lint inside the `expect` attribute is tracked individually, the `lint_index`
/// identifies the lint inside the attribute and ensures that the IDs are unique.
/// Setting for how to handle a lint.
///
-/// See: https://doc.rust-lang.org/rustc/lints/levels.html
+/// See: <https://doc.rust-lang.org/rustc/lints/levels.html>
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
pub enum Level {
/// The `allow` level will not issue any message.
-// check-pass
// ignore-tidy-linelength
#![feature(lint_reasons)]
let mut v = 0;
//~^ WARNING variable does not need to be mutable [unused_mut]
//~| NOTE this overrides the previous `expect` lint level and warns about the `unused_mut` lint here
+ //~| HELP remove this `mut`
}
}
+#[expect(unused_variables)]
+//~^ WARNING this lint expectation is unfulfilled
+#[forbid(unused_variables)]
+//~^ NOTE the lint level is defined here
+fn check_expect_then_forbid() {
+ let this_is_my_function = 3;
+ //~^ ERROR unused variable: `this_is_my_function` [unused_variables]
+ //~| HELP if this is intentional, prefix it with an underscore
+}
+
fn main() {}
+error: unused variable: `this_is_my_function`
+ --> $DIR/expect_nested_lint_levels.rs:48:9
+ |
+LL | let this_is_my_function = 3;
+ | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_this_is_my_function`
+ |
+note: the lint level is defined here
+ --> $DIR/expect_nested_lint_levels.rs:45:10
+ |
+LL | #[forbid(unused_variables)]
+ | ^^^^^^^^^^^^^^^^
+
warning: variable does not need to be mutable
- --> $DIR/expect_nested_lint_levels.rs:37:13
+ --> $DIR/expect_nested_lint_levels.rs:36:13
|
LL | let mut v = 0;
| ----^
|
= note: this overrides the previous `expect` lint level and warns about the `unused_mut` lint here
note: the lint level is defined here
- --> $DIR/expect_nested_lint_levels.rs:32:9
+ --> $DIR/expect_nested_lint_levels.rs:31:9
|
LL | unused_mut,
| ^^^^^^^^^^
warning: this lint expectation is unfulfilled
- --> $DIR/expect_nested_lint_levels.rs:24:5
+ --> $DIR/expect_nested_lint_levels.rs:23:5
|
LL | unused_mut,
| ^^^^^^^^^^
= note: this `expect` is overridden by a `warn` attribute before the `unused_mut` lint is triggered
warning: this lint expectation is unfulfilled
- --> $DIR/expect_nested_lint_levels.rs:8:5
+ --> $DIR/expect_nested_lint_levels.rs:7:5
|
LL | unused_mut,
| ^^^^^^^^^^
|
= note: this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered
-warning: 3 warnings emitted
+warning: this lint expectation is unfulfilled
+ --> $DIR/expect_nested_lint_levels.rs:43:10
+ |
+LL | #[expect(unused_variables)]
+ | ^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 4 warnings emitted
--- /dev/null
+#![feature(lint_reasons)]
+
+#[forbid(unused_variables)]
+//~^ NOTE `forbid` level set here
+//~| NOTE `forbid` level set here
+#[expect(unused_variables)]
+//~^ ERROR incompatible with previous forbid [E0453]
+//~| NOTE overruled by previous forbid
+//~| ERROR incompatible with previous forbid [E0453]
+//~| NOTE overruled by previous forbid
+fn expect_forbidden_lint_1() {}
+
+#[forbid(while_true)]
+//~^ NOTE `forbid` level set here
+//~| NOTE `forbid` level set here
+//~| NOTE the lint level is defined here
+#[expect(while_true)]
+//~^ ERROR incompatible with previous forbid [E0453]
+//~| NOTE overruled by previous forbid
+//~| ERROR incompatible with previous forbid [E0453]
+//~| NOTE overruled by previous forbid
+fn expect_forbidden_lint_2() {
+ // This while loop will produce a `while_true` lint as the lint level
+ // at this node is still `forbid` and the `while_true` check happens
+ // before the compilation terminates due to `E0453`
+ while true {}
+ //~^ ERROR denote infinite loops with `loop { ... }`
+ //~| HELP use `loop`
+}
+
+fn main() {
+ expect_forbidden_lint_1();
+ expect_forbidden_lint_2();
+}
--- /dev/null
+error[E0453]: expect(unused_variables) incompatible with previous forbid
+ --> $DIR/expect_with_forbid.rs:6:10
+ |
+LL | #[forbid(unused_variables)]
+ | ---------------- `forbid` level set here
+...
+LL | #[expect(unused_variables)]
+ | ^^^^^^^^^^^^^^^^ overruled by previous forbid
+
+error[E0453]: expect(while_true) incompatible with previous forbid
+ --> $DIR/expect_with_forbid.rs:17:10
+ |
+LL | #[forbid(while_true)]
+ | ---------- `forbid` level set here
+...
+LL | #[expect(while_true)]
+ | ^^^^^^^^^^ overruled by previous forbid
+
+error[E0453]: expect(unused_variables) incompatible with previous forbid
+ --> $DIR/expect_with_forbid.rs:6:10
+ |
+LL | #[forbid(unused_variables)]
+ | ---------------- `forbid` level set here
+...
+LL | #[expect(unused_variables)]
+ | ^^^^^^^^^^^^^^^^ overruled by previous forbid
+
+error[E0453]: expect(while_true) incompatible with previous forbid
+ --> $DIR/expect_with_forbid.rs:17:10
+ |
+LL | #[forbid(while_true)]
+ | ---------- `forbid` level set here
+...
+LL | #[expect(while_true)]
+ | ^^^^^^^^^^ overruled by previous forbid
+
+error: denote infinite loops with `loop { ... }`
+ --> $DIR/expect_with_forbid.rs:26:5
+ |
+LL | while true {}
+ | ^^^^^^^^^^ help: use `loop`
+ |
+note: the lint level is defined here
+ --> $DIR/expect_with_forbid.rs:13:10
+ |
+LL | #[forbid(while_true)]
+ | ^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0453`.