Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two let else regression tests #100443

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/test/ui/let-else/issue-94176.rs
Original file line number Diff line number Diff line change
@@ -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<u32>) -> Option<u32> { //~ ERROR mismatched types
let Some(_) = a else { return None; };
println!("Foo");
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/let-else/issue-94176.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0308]: mismatched types
--> $DIR/issue-94176.rs:5:32
|
LL | pub fn test(a: Option<u32>) -> Option<u32> {
| ---- ^^^^^^^^^^^ expected enum `Option`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Option<u32>`
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`.
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