Skip to content

Commit d549ede

Browse files
committed
let-else: add test for linting unused variables in the first place
+ remove actual unused vars from some other tests to be less distracting
1 parent 07539b8 commit d549ede

5 files changed

+24
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
// check-pass
21
// issue #89807
32

43
#![feature(let_else)]
54

65
#[deny(unused_variables)]
76

87
fn main() {
9-
let value = Some(String::new());
8+
let value = Some(5);
109
#[allow(unused)]
1110
let banana = 1;
1211
#[allow(unused)]
1312
let Some(chaenomeles) = value else { return }; // OK
13+
let Some(unused) = value else { return };
14+
//~^ ERROR unused variable: `unused`
1415
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `unused`
2+
--> $DIR/let-else-allow-unused.rs:13:14
3+
|
4+
LL | let Some(unused) = value else { return };
5+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
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-temp-borrowck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> {
1212

1313
fn let_else() {
1414
let x = String::from("Hey");
15-
let Ok(s) = foo(&x) else { return };
15+
let Ok(_) = foo(&x) else { return };
1616
}
1717

1818
fn if_let() {
1919
let x = String::from("Hey");
20-
let s = if let Ok(s) = foo(&x) { s } else { return };
20+
let _ = if let Ok(s) = foo(&x) { s } else { return };
2121
}
2222

2323
fn main() {

src/test/ui/let-else/let-else-then-diverge.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//
21
// popped up in in #94012, where an alternative desugaring was
3-
// causing unreachable code errors
2+
// causing unreachable code errors, and also we needed to check
3+
// that the desugaring's generated lints weren't applying to
4+
// the whole else block.
45

56
#![feature(let_else)]
67
#![deny(unused_variables)]

src/test/ui/let-else/let-else-then-diverge.stderr

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

0 commit comments

Comments
 (0)