Skip to content

Commit

Permalink
Split-off the passing tests to ensure they pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jan 18, 2024
1 parent d8b72e7 commit ff6fa67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
error: mismatched types
--> $DIR/typeck.rs:21:9
--> $DIR/typeck.rs:25: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
--> $DIR/typeck.rs:29: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
--> $DIR/typeck.rs:33: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
--> $DIR/typeck.rs:38: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
--> $DIR/typeck.rs:45: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
--> $DIR/typeck.rs:52: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
--> $DIR/typeck.rs:57: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
--> $DIR/typeck.rs:63:9
|
LL | !,
| ^ a never pattern must be used on an uninhabited type
Expand Down
25 changes: 16 additions & 9 deletions tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: pass fail
//[pass] check-pass
//[fail] check-fail
#![feature(never_patterns)]
#![feature(exhaustive_patterns)]
#![allow(incomplete_features)]
Expand All @@ -15,51 +18,55 @@ fn safe_unwrap_result<T: Copy>(res: Result<T, Void>) {
}

// Check we only accept `!` where we want to.
fn never_pattern_typeck(void: Void) {
#[cfg(fail)]
fn never_pattern_typeck_fail(void: Void) {
// Don't accept on a non-empty type.
match () {
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
match (0, false) {
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
match (0, false) {
(_, !),
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
match Some(0) {
None => {}
Some(!),
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}

// Don't accept on an arbitrary type, even if there are no more branches.
match () {
() => {}
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}

// Don't accept even on an empty branch.
match None::<Void> {
None => {}
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
match (&[] as &[Void]) {
[] => {}
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
// Let alone if the emptiness is behind a reference.
match None::<&Void> {
None => {}
!,
//~^ ERROR: mismatched types
//[fail]~^ ERROR: mismatched types
}
}

#[cfg(pass)]
fn never_pattern_typeck_pass(void: Void) {
// Participate in match ergonomics.
match &void {
!,
Expand Down

0 comments on commit ff6fa67

Please sign in to comment.