Skip to content

Commit

Permalink
let-else: add a test for warnings on let-else with diverging tail
Browse files Browse the repository at this point in the history
  • Loading branch information
cormacrelf authored and est31 committed Aug 12, 2022
1 parent e2b52ff commit e3c5bd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/ui/let-else/let-else-then-diverge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// popped up in in #94012, where an alternative desugaring was
// causing unreachable code errors

#![feature(let_else)]
#![deny(unused_variables)]
#![deny(unreachable_code)]

fn let_else_diverge() -> bool {
let Some(_) = Some("test") else {
let x = 5; //~ ERROR unused variable: `x`
return false;
};
return true;
}

fn main() {
let_else_diverge();
}
14 changes: 14 additions & 0 deletions src/test/ui/let-else/let-else-then-diverge.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unused variable: `x`
--> $DIR/let-else-then-diverge.rs:11: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
|
LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit e3c5bd6

Please sign in to comment.