Add tests
This commit is contained in:
parent
8424f8e8cd
commit
a947c4c2c3
@ -1,17 +0,0 @@
|
|||||||
error[E0005]: refutable pattern in local binding
|
|
||||||
--> $DIR/never_patterns.rs:10:9
|
|
||||||
|
|
|
||||||
LL | let Ok(_x) = res;
|
|
||||||
| ^^^^^^ pattern `Err(_)` not covered
|
|
||||||
|
|
|
||||||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
|
|
||||||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
|
|
||||||
= note: the matched value is of type `Result<T, Void>`
|
|
||||||
help: you might want to use `let else` to handle the variant that isn't matched
|
|
||||||
|
|
|
||||||
LL | let Ok(_x) = res else { todo!() };
|
|
||||||
| ++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0005`.
|
|
@ -1,63 +1,84 @@
|
|||||||
|
// check-pass
|
||||||
#![feature(never_patterns)]
|
#![feature(never_patterns)]
|
||||||
|
#![feature(exhaustive_patterns)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
enum Void {}
|
enum Void {}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
||||||
// The classic use for empty types.
|
// The classic use for empty types.
|
||||||
fn safe_unwrap_result<T>(res: Result<T, Void>) {
|
fn safe_unwrap_result<T: Copy>(res: Result<T, Void>) {
|
||||||
let Ok(_x) = res; //~ ERROR refutable pattern in local binding
|
let Ok(_x) = res;
|
||||||
let (Ok(_x) | Err(!)) = &res;
|
let (Ok(_x) | Err(!)) = &res;
|
||||||
let (Ok(_x) | Err(&!)) = res.as_ref();
|
let (Ok(_x) | Err(!)) = res.as_ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we only accept `!` where we want to.
|
// Check we only accept `!` where we want to.
|
||||||
fn never_pattern_location(void: Void) {
|
fn never_pattern_typeck(void: Void) {
|
||||||
// FIXME(never_patterns): Don't accept on a non-empty type.
|
// FIXME(never_patterns): Don't accept on a non-empty type.
|
||||||
|
match () {
|
||||||
|
!,
|
||||||
|
}
|
||||||
|
match (0, false) {
|
||||||
|
!,
|
||||||
|
}
|
||||||
|
match (0, false) {
|
||||||
|
(_, !),
|
||||||
|
}
|
||||||
match Some(0) {
|
match Some(0) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(!),
|
Some(!),
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
|
// FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
|
||||||
match () {
|
match () {
|
||||||
() => {}
|
() => {}
|
||||||
!,
|
!,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(never_patterns): Don't accept even on an empty branch.
|
// FIXME(never_patterns): Don't accept even on an empty branch.
|
||||||
match None::<Void> {
|
match None::<Void> {
|
||||||
None => {}
|
None => {}
|
||||||
!,
|
!,
|
||||||
}
|
}
|
||||||
|
match (&[] as &[Void]) {
|
||||||
|
[] => {}
|
||||||
|
!,
|
||||||
|
}
|
||||||
// FIXME(never_patterns): Let alone if the emptiness is behind a reference.
|
// FIXME(never_patterns): Let alone if the emptiness is behind a reference.
|
||||||
match None::<&Void> {
|
match None::<&Void> {
|
||||||
None => {}
|
None => {}
|
||||||
!,
|
!,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Participate in match ergonomics.
|
// Participate in match ergonomics.
|
||||||
match &void {
|
match &void {
|
||||||
!
|
!,
|
||||||
}
|
}
|
||||||
match &&void {
|
match &&void {
|
||||||
!
|
!,
|
||||||
}
|
}
|
||||||
match &&void {
|
match &&void {
|
||||||
&!
|
&!,
|
||||||
}
|
}
|
||||||
match &None::<Void> {
|
match &None::<Void> {
|
||||||
None => {}
|
None => {}
|
||||||
Some(!)
|
Some(!),
|
||||||
}
|
}
|
||||||
match None::<&Void> {
|
match None::<&Void> {
|
||||||
None => {}
|
None => {}
|
||||||
Some(!),
|
Some(!),
|
||||||
}
|
}
|
||||||
// Accept on a composite empty type.
|
|
||||||
match None::<&(u32, Void)> {
|
// Accept on a directly empty type.
|
||||||
None => {}
|
match void {
|
||||||
Some(&!),
|
!,
|
||||||
|
}
|
||||||
|
match &void {
|
||||||
|
&!,
|
||||||
}
|
}
|
||||||
// Accept on an simple empty type.
|
|
||||||
match None::<Void> {
|
match None::<Void> {
|
||||||
None => {}
|
None => {}
|
||||||
Some(!),
|
Some(!),
|
||||||
@ -70,4 +91,21 @@ fn never_pattern_location(void: Void) {
|
|||||||
None => {}
|
None => {}
|
||||||
Some(&(_, !)),
|
Some(&(_, !)),
|
||||||
}
|
}
|
||||||
|
match (&[] as &[Void]) {
|
||||||
|
[] => {}
|
||||||
|
[!],
|
||||||
|
}
|
||||||
|
// Accept on a composite empty type.
|
||||||
|
match None::<&(u32, Void)> {
|
||||||
|
None => {}
|
||||||
|
Some(&!),
|
||||||
|
}
|
||||||
|
match None::<&(u32, Void)> {
|
||||||
|
None => {}
|
||||||
|
Some(!),
|
||||||
|
}
|
||||||
|
match None::<&Result<Void, Void>> {
|
||||||
|
None => {}
|
||||||
|
Some(!),
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user