diff --git a/src/test/ui/let-else/issue-94176.rs b/src/test/ui/let-else/issue-94176.rs new file mode 100644 index 000000000000..e35bbd888306 --- /dev/null +++ b/src/test/ui/let-else/issue-94176.rs @@ -0,0 +1,10 @@ +// Issue #94176: wrong span for the error message of a mismatched type error, +// if the function uses a `let else` construct. +#![feature(let_else)] + +pub fn test(a: Option) -> Option { //~ ERROR mismatched types + let Some(_) = a else { return None; }; + println!("Foo"); +} + +fn main() {} diff --git a/src/test/ui/let-else/issue-94176.stderr b/src/test/ui/let-else/issue-94176.stderr new file mode 100644 index 000000000000..0cb97aceebfd --- /dev/null +++ b/src/test/ui/let-else/issue-94176.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/issue-94176.rs:5:32 + | +LL | pub fn test(a: Option) -> Option { + | ---- ^^^^^^^^^^^ expected enum `Option`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected enum `Option` + found unit type `()` +help: consider returning the local binding `a` + | +LL ~ println!("Foo"); +LL + a + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. 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 000000000000..49633d943bee --- /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 000000000000..ceb61029d386 --- /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 +