2023-11-21 19:30:43 -06:00
|
|
|
// Check that never patterns require the feature gate.
|
|
|
|
use std::ptr::NonNull;
|
|
|
|
|
|
|
|
enum Void {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let res: Result<u32, Void> = Ok(0);
|
|
|
|
let (Ok(_x) | Err(&!)) = res.as_ref();
|
|
|
|
//~^ ERROR `!` patterns are experimental
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let ptr: *const Void = NonNull::dangling().as_ptr();
|
|
|
|
match *ptr {
|
2023-12-12 06:33:39 -06:00
|
|
|
!
|
|
|
|
//~^ ERROR `!` patterns are experimental
|
|
|
|
}
|
|
|
|
// Check that the gate operates even behind `cfg`.
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
match *ptr {
|
|
|
|
!
|
|
|
|
//~^ ERROR `!` patterns are experimental
|
|
|
|
}
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
match *ptr {
|
|
|
|
! => {}
|
|
|
|
//~^ ERROR `!` patterns are experimental
|
2023-11-21 19:30:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-12 06:33:39 -06:00
|
|
|
// Correctly gate match arms with no body.
|
|
|
|
match Some(0) {
|
|
|
|
None => {}
|
|
|
|
Some(_),
|
|
|
|
//~^ ERROR unexpected `,` in pattern
|
|
|
|
}
|
|
|
|
match Some(0) {
|
|
|
|
None => {}
|
|
|
|
Some(_)
|
|
|
|
//~^ ERROR `match` arm with no body
|
|
|
|
}
|
|
|
|
match Some(0) {
|
|
|
|
_ => {}
|
|
|
|
Some(_) if false,
|
|
|
|
//~^ ERROR `match` arm with no body
|
|
|
|
Some(_) if false
|
|
|
|
//~^ ERROR `match` arm with no body
|
|
|
|
}
|
|
|
|
match res {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(!),
|
2023-12-12 07:52:05 -06:00
|
|
|
//~^ ERROR `!` patterns are experimental
|
2023-12-12 06:33:39 -06:00
|
|
|
}
|
|
|
|
match res {
|
|
|
|
Err(!) if false,
|
2023-12-12 07:52:05 -06:00
|
|
|
//~^ ERROR `!` patterns are experimental
|
2023-12-12 06:33:39 -06:00
|
|
|
//~| ERROR a guard on a never pattern will never be run
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2023-11-21 19:30:43 -06:00
|
|
|
// Check that the gate operates even behind `cfg`.
|
2023-12-12 06:33:39 -06:00
|
|
|
match Some(0) {
|
|
|
|
None => {}
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
Some(_)
|
|
|
|
//~^ ERROR `match` arm with no body
|
|
|
|
}
|
|
|
|
match Some(0) {
|
|
|
|
_ => {}
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
Some(_) if false
|
|
|
|
//~^ ERROR `match` arm with no body
|
2023-11-21 19:30:43 -06:00
|
|
|
}
|
|
|
|
}
|