rust/tests/ui/feature-gates/feature-gate-never_patterns.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.7 KiB
Rust
Raw Normal View History

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 {
!
//~^ 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
}
}
// 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
}
match res {
Err(!) if false,
2023-12-12 07:52:05 -06:00
//~^ ERROR `!` patterns are experimental
//~| 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`.
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
}
}