2024-02-07 17:09:31 -06:00
|
|
|
#![feature(never_patterns)]
|
|
|
|
#![allow(incomplete_features)]
|
|
|
|
|
|
|
|
enum Void {}
|
|
|
|
|
|
|
|
// EMIT_MIR never_patterns.opt1.SimplifyCfg-initial.after.mir
|
|
|
|
fn opt1(res: &Result<u32, Void>) -> &u32 {
|
2024-02-19 21:07:50 -06:00
|
|
|
// CHECK-LABEL: fn opt1(
|
|
|
|
// CHECK: bb0: {
|
|
|
|
// CHECK-NOT: {{bb.*}}: {
|
|
|
|
// CHECK: return;
|
2024-02-07 17:09:31 -06:00
|
|
|
match res {
|
|
|
|
Ok(x) => x,
|
|
|
|
Err(!),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 21:07:50 -06:00
|
|
|
// EMIT_MIR never_patterns.opt2.SimplifyCfg-initial.after.mir
|
|
|
|
fn opt2(res: &Result<u32, Void>) -> &u32 {
|
|
|
|
// CHECK-LABEL: fn opt2(
|
|
|
|
// CHECK: bb0: {
|
|
|
|
// CHECK-NOT: {{bb.*}}: {
|
|
|
|
// CHECK: return;
|
|
|
|
match res {
|
|
|
|
Ok(x) | Err(!) => x,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR never_patterns.opt3.SimplifyCfg-initial.after.mir
|
|
|
|
fn opt3(res: &Result<u32, Void>) -> &u32 {
|
|
|
|
// CHECK-LABEL: fn opt3(
|
|
|
|
// CHECK: bb0: {
|
|
|
|
// CHECK-NOT: {{bb.*}}: {
|
|
|
|
// CHECK: return;
|
|
|
|
match res {
|
|
|
|
Err(!) | Ok(x) => x,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 17:09:31 -06:00
|
|
|
fn main() {
|
2024-02-19 21:07:50 -06:00
|
|
|
assert_eq!(opt1(&Ok(0)), &0);
|
|
|
|
assert_eq!(opt2(&Ok(0)), &0);
|
|
|
|
assert_eq!(opt3(&Ok(0)), &0);
|
2024-02-07 17:09:31 -06:00
|
|
|
}
|