mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Test expect
with forbid
and fix doc errors (RFC-2383)
* Add test to expect and the forbid a lint (RFC 2383)
This commit is contained in:
parent
aa2a0a83d9
commit
43dc430f52
@ -50,10 +50,9 @@ pub enum Applicability {
|
||||
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
|
||||
@ -61,8 +60,7 @@ pub enum Applicability {
|
||||
/// 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.
|
||||
@ -135,7 +133,7 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
|
||||
|
||||
/// 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.
|
||||
|
@ -1,4 +1,3 @@
|
||||
// check-pass
|
||||
// ignore-tidy-linelength
|
||||
|
||||
#![feature(lint_reasons)]
|
||||
@ -37,7 +36,18 @@ mod oof {
|
||||
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() {}
|
||||
|
@ -1,5 +1,17 @@
|
||||
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;
|
||||
| ----^
|
||||
@ -8,13 +20,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,
|
||||
| ^^^^^^^^^^
|
||||
@ -23,12 +35,18 @@ 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
|
||||
|
||||
|
34
src/test/ui/lint/rfc-2383-lint-reason/expect_with_forbid.rs
Normal file
34
src/test/ui/lint/rfc-2383-lint-reason/expect_with_forbid.rs
Normal file
@ -0,0 +1,34 @@
|
||||
#![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();
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
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`.
|
Loading…
Reference in New Issue
Block a user