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 0000000000000..e35bbd8883062 --- /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 0000000000000..0cb97aceebfd5 --- /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`.