rust/tests/mir-opt/building/match/never_patterns.rs

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

45 lines
980 B
Rust
Raw Normal View History

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 {
// 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(!),
}
}
// 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() {
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
}