Skip to content

Commit a09e2f6

Browse files
authored
Rollup merge of #102761 - est31:let_else_uninhabited_test, r=compiler-errors
let-else: test else block with non-never uninhabited type let else currently does not allow uninhabited types for the `else` block that aren't `!`. One can maybe think about relaxing this in the future, but if it is done, it should be an explicit choice and not an unexpected side effect of e.g. a refactor. Thus, I'm extending a test that will fail if the behaviour changes.
2 parents 04459f7 + 58fb351 commit a09e2f6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: src/test/ui/let-else/let-else-non-diverging.rs

+11
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ fn main() {
88
}
99
};
1010
let Some(x) = Some(1) else { Some(2) }; //~ ERROR does not diverge
11+
12+
// Ensure that uninhabited types do not "diverge".
13+
// This might be relaxed in the future, but when it is,
14+
// it should be an explicitly wanted descision.
15+
let Some(x) = Some(1) else { foo::<Uninhabited>() }; //~ ERROR does not diverge
16+
}
17+
18+
enum Uninhabited {}
19+
20+
fn foo<T>() -> T {
21+
panic!()
1122
}

Diff for: src/test/ui/let-else/let-else-non-diverging.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ LL | let Some(x) = Some(1) else { Some(2) };
3939
= help: try adding a diverging expression, such as `return` or `panic!(..)`
4040
= help: ...or use `match` instead of `let...else`
4141

42-
error: aborting due to 3 previous errors
42+
error[E0308]: `else` clause of `let...else` does not diverge
43+
--> $DIR/let-else-non-diverging.rs:15:32
44+
|
45+
LL | let Some(x) = Some(1) else { foo::<Uninhabited>() };
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `!`, found enum `Uninhabited`
47+
|
48+
= note: expected type `!`
49+
found enum `Uninhabited`
50+
= help: try adding a diverging expression, such as `return` or `panic!(..)`
51+
= help: ...or use `match` instead of `let...else`
52+
53+
error: aborting due to 4 previous errors
4354

4455
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)