Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let-else: test else block with non-never uninhabited type #102761

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/test/ui/let-else/let-else-non-diverging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}
13 changes: 12 additions & 1 deletion src/test/ui/let-else/let-else-non-diverging.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.