Skip to content

Commit f8656ef

Browse files
committed
Update unreachable_enum_default_branch.rs
1 parent a10d157 commit f8656ef

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

tests/codegen/enum/uninhabited_enum_default_branch.rs

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ compile-flags: -O
2+
3+
#![crate_type = "lib"]
4+
5+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6+
pub struct Int(u32);
7+
8+
const A: Int = Int(201);
9+
const B: Int = Int(270);
10+
const C: Int = Int(153);
11+
12+
// The code is from https://github.com/rust-lang/rust/issues/119520.
13+
// This code will basically turn into `matches!(x.partial_cmp(&A), Some(Greater | Equal))`.
14+
// The otherwise branch must be `Less`.
15+
// CHECK-LABEL: @implicit_match(
16+
// CHECK-SAME: [[TMP0:%.*]])
17+
// CHECK-NEXT: start:
18+
// CHECK-NEXT: [[TMP1:%.*]] = add i32 [[TMP0]], -201
19+
// CHECK-NEXT: icmp ult i32 [[TMP1]], 70
20+
// CHECK-NEXT: icmp eq i32 [[TMP0]], 153
21+
// CHECK-NEXT: [[SPEC_SELECT:%.*]] = or i1
22+
// CHECK-NEXT: ret i1 [[SPEC_SELECT]]
23+
#[no_mangle]
24+
pub fn implicit_match(x: Int) -> bool {
25+
(x >= A && x <= B)
26+
|| x == C
27+
}
28+
29+
// The code is from https://github.com/rust-lang/rust/issues/110097.
30+
// We expect it to generate the same optimized code as a full match.
31+
// CHECK-LABEL: @if_let(
32+
// CHECK-NEXT: start:
33+
// CHECK-NEXT: insertvalue
34+
// CHECK-NEXT: insertvalue
35+
// CHECK-NEXT: ret
36+
#[no_mangle]
37+
pub fn if_let(val: Result<i32, ()>) -> Result<i32, ()> {
38+
if let Ok(x) = val {
39+
Ok(x)
40+
} else {
41+
Err(())
42+
}
43+
}

0 commit comments

Comments
 (0)