Skip to content

Commit

Permalink
let-else: add test for linting unused variables in the first place
Browse files Browse the repository at this point in the history
+ remove actual unused vars from some other tests to be less distracting
  • Loading branch information
cormacrelf committed Feb 16, 2022
1 parent 07539b8 commit d549ede
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/test/ui/let-else/let-else-allow-unused.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// check-pass
// issue #89807

#![feature(let_else)]

#[deny(unused_variables)]

fn main() {
let value = Some(String::new());
let value = Some(5);
#[allow(unused)]
let banana = 1;
#[allow(unused)]
let Some(chaenomeles) = value else { return }; // OK
let Some(unused) = value else { return };
//~^ ERROR unused variable: `unused`
}
14 changes: 14 additions & 0 deletions src/test/ui/let-else/let-else-allow-unused.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unused variable: `unused`
--> $DIR/let-else-allow-unused.rs:13:14
|
LL | let Some(unused) = value else { return };
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
|
note: the lint level is defined here
--> $DIR/let-else-allow-unused.rs:5:8
|
LL | #[deny(unused_variables)]
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/let-else/let-else-temp-borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> {

fn let_else() {
let x = String::from("Hey");
let Ok(s) = foo(&x) else { return };
let Ok(_) = foo(&x) else { return };
}

fn if_let() {
let x = String::from("Hey");
let s = if let Ok(s) = foo(&x) { s } else { return };
let _ = if let Ok(s) = foo(&x) { s } else { return };
}

fn main() {
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/let-else/let-else-then-diverge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// popped up in in #94012, where an alternative desugaring was
// causing unreachable code errors
// causing unreachable code errors, and also we needed to check
// that the desugaring's generated lints weren't applying to
// the whole else block.

#![feature(let_else)]
#![deny(unused_variables)]
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/let-else/let-else-then-diverge.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: unused variable: `x`
--> $DIR/let-else-then-diverge.rs:11:13
--> $DIR/let-else-then-diverge.rs:12:13
|
LL | let x = 5;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
note: the lint level is defined here
--> $DIR/let-else-then-diverge.rs:6:9
--> $DIR/let-else-then-diverge.rs:7:9
|
LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit d549ede

Please sign in to comment.