Skip to content

Commit

Permalink
Rollup merge of rust-lang#100443 - est31:let_else_regression_tests, r…
Browse files Browse the repository at this point in the history
…=Mark-Simulacrum

Add two let else regression tests

Adds a regression test for rust-lang#94176, as it was fixed by rust-lang#98574 but doesn't have a regression test. The PR also incorporates a commit from rust-lang#94012 which added a test for an issue discovered in that PR.

Originally they have been part of rust-lang#99291, but I've moved them out in the hopes of getting them merged more quickly, as that PR is already open since a month, and so that rust-lang#99291 can focus on the drop order part of things.

Closes rust-lang#94176
Closes rust-lang#96961 -- dupe of rust-lang#94176
  • Loading branch information
Dylan-DPC committed Aug 12, 2022
2 parents 0356034 + 9818526 commit 3bc30bb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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

0 comments on commit 3bc30bb

Please sign in to comment.