From 58fb351cad389b660c82966e28e213e77dfc1c57 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 7 Oct 2022 02:42:02 +0200 Subject: [PATCH] let-else: test else block with non-never uninhabited type --- src/test/ui/let-else/let-else-non-diverging.rs | 11 +++++++++++ src/test/ui/let-else/let-else-non-diverging.stderr | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/ui/let-else/let-else-non-diverging.rs b/src/test/ui/let-else/let-else-non-diverging.rs index b5bd91ceb9e75..58d2c09776f98 100644 --- a/src/test/ui/let-else/let-else-non-diverging.rs +++ b/src/test/ui/let-else/let-else-non-diverging.rs @@ -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::() }; //~ ERROR does not diverge +} + +enum Uninhabited {} + +fn foo() -> T { + panic!() } diff --git a/src/test/ui/let-else/let-else-non-diverging.stderr b/src/test/ui/let-else/let-else-non-diverging.stderr index c999a54952560..78551fcc434a8 100644 --- a/src/test/ui/let-else/let-else-non-diverging.stderr +++ b/src/test/ui/let-else/let-else-non-diverging.stderr @@ -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::() }; + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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`.