forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let-else: add a test for warnings on let-else with diverging tail
- Loading branch information
1 parent
e2b52ff
commit e3c5bd6
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|