mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
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.
This commit is contained in:
commit
a09e2f6753
@ -8,4 +8,15 @@ fn main() {
|
||||
}
|
||||
};
|
||||
let Some(x) = Some(1) else { Some(2) }; //~ ERROR does not diverge
|
||||
|
||||
// Ensure that uninhabited types do not "diverge".
|
||||
// This might be relaxed in the future, but when it is,
|
||||
// it should be an explicitly wanted descision.
|
||||
let Some(x) = Some(1) else { foo::<Uninhabited>() }; //~ ERROR does not diverge
|
||||
}
|
||||
|
||||
enum Uninhabited {}
|
||||
|
||||
fn foo<T>() -> T {
|
||||
panic!()
|
||||
}
|
||||
|
@ -39,6 +39,17 @@ LL | let Some(x) = Some(1) else { Some(2) };
|
||||
= help: try adding a diverging expression, such as `return` or `panic!(..)`
|
||||
= help: ...or use `match` instead of `let...else`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0308]: `else` clause of `let...else` does not diverge
|
||||
--> $DIR/let-else-non-diverging.rs:15:32
|
||||
|
|
||||
LL | let Some(x) = Some(1) else { foo::<Uninhabited>() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `!`, found enum `Uninhabited`
|
||||
|
|
||||
= note: expected type `!`
|
||||
found enum `Uninhabited`
|
||||
= help: try adding a diverging expression, such as `return` or `panic!(..)`
|
||||
= help: ...or use `match` instead of `let...else`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
Loading…
Reference in New Issue
Block a user