Skip to content

Commit 5e176b0

Browse files
committed
Added expect attribute tests (RFC 2383)
1 parent d073638 commit 5e176b0

16 files changed

+225
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#[expect(unused_variables, reason = "All emissions should be consumed by the nested expect")]
6+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
7+
//~| NOTE #[warn(unfulfilled_lint_expectation)]` on by default
8+
//~| NOTE All emissions should be consumed by the nested expect
9+
mod oof {
10+
#[expect(unused_variables, reason = "This should collect all unused variable emissions")]
11+
fn bar() {
12+
let mut c = 0;
13+
let mut l = 0;
14+
let mut l = 0;
15+
let mut i = 0;
16+
let mut p = 0;
17+
let mut y = 0;
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect-consumes-all-warnings.rs:5:1
3+
|
4+
LL | #[expect(unused_variables, reason = "All emissions should be consumed by the nested expect")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectation)]` on by default
8+
= note: All emissions should be consumed by the nested expect
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#![expect(unused_mut)]
6+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect_as_crate_attribute.rs:5:1
3+
|
4+
LL | #![expect(unused_mut)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectation)]` on by default
8+
9+
warning: 1 warning emitted
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#![expect(unused_variables, reason = "<This should fail and display this reason>")]
6+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
7+
//~| NOTE `#[warn(unfulfilled_lint_expectation)]` on by default
8+
//~| NOTE <This should fail and display this reason>
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect_reason.rs:5:1
3+
|
4+
LL | #![expect(unused_variables, reason = "<This should fail and display this reason>")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectation)]` on by default
8+
= note: <This should fail and display this reason>
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#[expect(unused_mut, reason = "This should trigger because `unused_mut` was allow")]
6+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
7+
//~| NOTE `#[warn(unfulfilled_lint_expectation)]` on by default
8+
//~| NOTE This should trigger because `unused_mut` was allow
9+
mod foo {
10+
fn bar() {
11+
#[allow(unused_mut, reason = "v is unused")]
12+
let mut v = 0;
13+
}
14+
}
15+
16+
#[expect(unused_mut, reason = "This should trigger because `unused_mut` is no longer expected")]
17+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
18+
//~| NOTE This should trigger because `unused_mut` is no longer expected
19+
mod oof {
20+
#[warn(unused_mut, reason = "We no longer expect it in this scope")]
21+
//~^ NOTE the lint level is defined here
22+
fn bar() {
23+
let mut v = 0;
24+
//~^ WARNING variable does not need to be mutable [unused_mut]
25+
//~| NOTE We no longer expect it in this scope
26+
}
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
warning: variable does not need to be mutable
2+
--> $DIR/expect_with_nested_levels.rs:23:13
3+
|
4+
LL | let mut v = 0;
5+
| ----^
6+
| |
7+
| help: remove this `mut`
8+
|
9+
= note: We no longer expect it in this scope
10+
note: the lint level is defined here
11+
--> $DIR/expect_with_nested_levels.rs:20:12
12+
|
13+
LL | #[warn(unused_mut, reason = "We no longer expect it in this scope")]
14+
| ^^^^^^^^^^
15+
16+
warning: this lint expectation is unfulfilled
17+
--> $DIR/expect_with_nested_levels.rs:5:1
18+
|
19+
LL | #[expect(unused_mut, reason = "This should trigger because `unused_mut` was allow")]
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: `#[warn(unfulfilled_lint_expectation)]` on by default
23+
= note: This should trigger because `unused_mut` was allow
24+
25+
warning: this lint expectation is unfulfilled
26+
--> $DIR/expect_with_nested_levels.rs:16:1
27+
|
28+
LL | #[expect(unused_mut, reason = "This should trigger because `unused_mut` is no longer expected")]
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: This should trigger because `unused_mut` is no longer expected
32+
33+
warning: 3 warnings emitted
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#[expect(unfulfilled_lint_expectation, reason = "this should catch the nested expect")]
6+
mod foo {
7+
#[expect(unfulfilled_lint_expectation, reason = "issuing a lint and getting caught above")]
8+
fn bar() {
9+
#[expect(unused_mut, reason = "v is unused")]
10+
let mut v = 0;
11+
}
12+
}
13+
14+
// make sure it doesn't catch itself
15+
#[expect(unfulfilled_lint_expectation, reason = "this should issue a warning")]
16+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectation]
17+
//~| NOTE `#[warn(unfulfilled_lint_expectation)]` on by default
18+
//~| NOTE this should issue a warning
19+
mod oof {}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expecting_missed_expectations.rs:15:1
3+
|
4+
LL | #[expect(unfulfilled_lint_expectation, reason = "this should issue a warning")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectation)]` on by default
8+
= note: this should issue a warning
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(lint_reasons)]
2+
3+
#![expect(reason = "This should trigger because `unused_mut` was allow", unused_mut)]
4+
//~^ ERROR malformed lint attribute
5+
//~| ERROR malformed lint attribute
6+
//~| NOTE reason in lint attribute must come last
7+
//~| NOTE reason in lint attribute must come last
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0452]: malformed lint attribute input
2+
--> $DIR/invalid_expect_attribute.rs:3:11
3+
|
4+
LL | #![expect(reason = "This should trigger because `unused_mut` was allow", unused_mut)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
6+
7+
error[E0452]: malformed lint attribute input
8+
--> $DIR/invalid_expect_attribute.rs:3:11
9+
|
10+
LL | #![expect(reason = "This should trigger because `unused_mut` was allow", unused_mut)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0452`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#![expect(unconditional_panic, unused, reason = "Don't trigger because `unused` was triggered")]
6+
fn main() {
7+
let x = 0;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#![expect(
6+
clippy::almost_swapped,
7+
reason = "This should be ignored in a normal run but trigger in a clippy run")]
8+
fn main() {
9+
// See lint doc https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
5+
#![expect(this_lint_does_not_exist)]
6+
//~^ WARNING unknown lint: `this_lint_does_not_exist` [unknown_lints]
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: unknown lint: `this_lint_does_not_exist`
2+
--> $DIR/unknown_lint_in_expect.rs:5:11
3+
|
4+
LL | #![expect(this_lint_does_not_exist)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unknown_lints)]` on by default
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)