Skip to content

Commit e7730dc

Browse files
committed
Expand let-else allow tests
The #[allow(...)] directive was tested for the body and the pattern, but non-presence of it wasn't tested. Furthermore, it wasn't tested for the expression. We add expression tests as well as ones checking the non-presence of the directive.
1 parent c1aa854 commit e7730dc

6 files changed

+80
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(let_else)]
2+
3+
#![deny(unused_variables)]
4+
5+
fn main() {
6+
let Some(_): Option<u32> = ({
7+
let x = 1; //~ ERROR unused variable: `x`
8+
Some(1)
9+
}) else {
10+
return;
11+
};
12+
13+
#[allow(unused_variables)]
14+
let Some(_): Option<u32> = ({
15+
let x = 1;
16+
Some(1)
17+
}) else {
18+
return;
19+
};
20+
21+
let Some(_): Option<u32> = ({
22+
#[allow(unused_variables)]
23+
let x = 1;
24+
Some(1)
25+
}) else {
26+
return;
27+
};
28+
29+
let x = 1; //~ ERROR unused variable: `x`
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unused variable: `x`
2+
--> $DIR/let-else-allow-in-expr.rs:7:13
3+
|
4+
LL | let x = 1;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/let-else-allow-in-expr.rs:3:9
9+
|
10+
LL | #![deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: unused variable: `x`
14+
--> $DIR/let-else-allow-in-expr.rs:29:9
15+
|
16+
LL | let x = 1;
17+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
18+
19+
error: aborting due to 2 previous errors
20+

src/test/ui/let-else/let-else-allow-unused.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// check-pass
21
// issue #89807
32

43
#![feature(let_else)]
@@ -10,5 +9,7 @@ fn main() {
109
#[allow(unused)]
1110
let banana = 1;
1211
#[allow(unused)]
13-
let Some(chaenomeles) = value else { return }; // OK
12+
let Some(chaenomeles) = value.clone() else { return }; // OK
13+
14+
let Some(chaenomeles) = value else { return }; //~ ERROR unused variable: `chaenomeles`
1415
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `chaenomeles`
2+
--> $DIR/let-else-allow-unused.rs:14:14
3+
|
4+
LL | let Some(chaenomeles) = value else { return };
5+
| ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_chaenomeles`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/let-else-allow-unused.rs:5:8
9+
|
10+
LL | #[deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

src/test/ui/let-else/let-else-check.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ fn main() {
1010
return;
1111
};
1212

13+
let Some(_): Option<u32> = Some(Default::default()) else {
14+
let x = 1; //~ ERROR unused variable: `x`
15+
return;
16+
};
17+
1318
let x = 1; //~ ERROR unused variable: `x`
1419
}

src/test/ui/let-else/let-else-check.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unused variable: `x`
2-
--> $DIR/let-else-check.rs:13:9
2+
--> $DIR/let-else-check.rs:18:9
33
|
44
LL | let x = 1;
55
| ^ help: if this is intentional, prefix it with an underscore: `_x`
@@ -10,5 +10,11 @@ note: the lint level is defined here
1010
LL | #![deny(unused_variables)]
1111
| ^^^^^^^^^^^^^^^^
1212

13-
error: aborting due to previous error
13+
error: unused variable: `x`
14+
--> $DIR/let-else-check.rs:14:13
15+
|
16+
LL | let x = 1;
17+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
18+
19+
error: aborting due to 2 previous errors
1420

0 commit comments

Comments
 (0)