Typecheck never patterns

This commit is contained in:
Nadrieril 2024-01-05 17:21:09 +01:00
parent a947c4c2c3
commit d8b72e796e
6 changed files with 110 additions and 7 deletions

View file

@ -1,4 +1,3 @@
// check-pass
#![feature(never_patterns)]
#![feature(exhaustive_patterns)]
#![allow(incomplete_features)]
@ -17,40 +16,48 @@ fn safe_unwrap_result<T: Copy>(res: Result<T, Void>) {
// Check we only accept `!` where we want to.
fn never_pattern_typeck(void: Void) {
// FIXME(never_patterns): Don't accept on a non-empty type.
// Don't accept on a non-empty type.
match () {
!,
//~^ ERROR: mismatched types
}
match (0, false) {
!,
//~^ ERROR: mismatched types
}
match (0, false) {
(_, !),
//~^ ERROR: mismatched types
}
match Some(0) {
None => {}
Some(!),
//~^ ERROR: mismatched types
}
// FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
// Don't accept on an arbitrary type, even if there are no more branches.
match () {
() => {}
!,
//~^ ERROR: mismatched types
}
// FIXME(never_patterns): Don't accept even on an empty branch.
// Don't accept even on an empty branch.
match None::<Void> {
None => {}
!,
//~^ ERROR: mismatched types
}
match (&[] as &[Void]) {
[] => {}
!,
//~^ ERROR: mismatched types
}
// FIXME(never_patterns): Let alone if the emptiness is behind a reference.
// Let alone if the emptiness is behind a reference.
match None::<&Void> {
None => {}
!,
//~^ ERROR: mismatched types
}
// Participate in match ergonomics.

View file

@ -0,0 +1,66 @@
error: mismatched types
--> $DIR/typeck.rs:21:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`
error: mismatched types
--> $DIR/typeck.rs:25:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `(i32, bool)`
error: mismatched types
--> $DIR/typeck.rs:29:13
|
LL | (_, !),
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `bool`
error: mismatched types
--> $DIR/typeck.rs:34:14
|
LL | Some(!),
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `i32`
error: mismatched types
--> $DIR/typeck.rs:41:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`
error: mismatched types
--> $DIR/typeck.rs:48:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `Option<Void>`
error: mismatched types
--> $DIR/typeck.rs:53:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `[Void]`
error: mismatched types
--> $DIR/typeck.rs:59:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `Option<&Void>`
error: aborting due to 8 previous errors