Skip to content

Commit 3bc30bb

Browse files
authored
Rollup merge of rust-lang#100443 - est31:let_else_regression_tests, r=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
2 parents 0356034 + 9818526 commit 3bc30bb

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

src/test/ui/let-else/issue-94176.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Issue #94176: wrong span for the error message of a mismatched type error,
2+
// if the function uses a `let else` construct.
3+
#![feature(let_else)]
4+
5+
pub fn test(a: Option<u32>) -> Option<u32> { //~ ERROR mismatched types
6+
let Some(_) = a else { return None; };
7+
println!("Foo");
8+
}
9+
10+
fn main() {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-94176.rs:5:32
3+
|
4+
LL | pub fn test(a: Option<u32>) -> Option<u32> {
5+
| ---- ^^^^^^^^^^^ expected enum `Option`, found `()`
6+
| |
7+
| implicitly returns `()` as its body has no tail or `return` expression
8+
|
9+
= note: expected enum `Option<u32>`
10+
found unit type `()`
11+
help: consider returning the local binding `a`
12+
|
13+
LL ~ println!("Foo");
14+
LL + a
15+
|
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// popped up in in #94012, where an alternative desugaring was
3+
// causing unreachable code errors
4+
5+
#![feature(let_else)]
6+
#![deny(unused_variables)]
7+
#![deny(unreachable_code)]
8+
9+
fn let_else_diverge() -> bool {
10+
let Some(_) = Some("test") else {
11+
let x = 5; //~ ERROR unused variable: `x`
12+
return false;
13+
};
14+
return true;
15+
}
16+
17+
fn main() {
18+
let_else_diverge();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `x`
2+
--> $DIR/let-else-then-diverge.rs:11:13
3+
|
4+
LL | let x = 5;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/let-else-then-diverge.rs:6:9
9+
|
10+
LL | #![deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)