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
5 changed files with 124 additions and 13 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue