From e3c5bd617d040b5ee0bc79e6e7f01772adce791b Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Tue, 15 Feb 2022 17:42:50 +1100 Subject: [PATCH] let-else: add a test for warnings on let-else with diverging tail --- src/test/ui/let-else/let-else-then-diverge.rs | 19 +++++++++++++++++++ .../ui/let-else/let-else-then-diverge.stderr | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/ui/let-else/let-else-then-diverge.rs create mode 100644 src/test/ui/let-else/let-else-then-diverge.stderr diff --git a/src/test/ui/let-else/let-else-then-diverge.rs b/src/test/ui/let-else/let-else-then-diverge.rs new file mode 100644 index 0000000000000..49633d943beea --- /dev/null +++ b/src/test/ui/let-else/let-else-then-diverge.rs @@ -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(); +} diff --git a/src/test/ui/let-else/let-else-then-diverge.stderr b/src/test/ui/let-else/let-else-then-diverge.stderr new file mode 100644 index 0000000000000..ceb61029d3863 --- /dev/null +++ b/src/test/ui/let-else/let-else-then-diverge.stderr @@ -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 +