Skip to content

Commit a62e9f8

Browse files
committed
Add a mir pre-codegen test for if T::ASSOC_CONST
1 parent ef49365 commit a62e9f8

3 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// MIR for `check_bool` after PreCodegen
2+
3+
fn check_bool() -> u32 {
4+
let mut _0: u32;
5+
let mut _1: bool;
6+
7+
bb0: {
8+
StorageLive(_1);
9+
_1 = const <T as TraitWithBool>::FLAG;
10+
switchInt(move _1) -> [0: bb1, otherwise: bb2];
11+
}
12+
13+
bb1: {
14+
_0 = const 456_u32;
15+
goto -> bb3;
16+
}
17+
18+
bb2: {
19+
_0 = const 123_u32;
20+
goto -> bb3;
21+
}
22+
23+
bb3: {
24+
StorageDead(_1);
25+
return;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// MIR for `check_int` after PreCodegen
2+
3+
fn check_int() -> u32 {
4+
let mut _0: u32;
5+
let mut _1: i32;
6+
7+
bb0: {
8+
StorageLive(_1);
9+
_1 = const <T as TraitWithInt>::VALUE;
10+
switchInt(_1) -> [1: bb1, 2: bb2, 3: bb3, otherwise: bb4];
11+
}
12+
13+
bb1: {
14+
_0 = const 123_u32;
15+
goto -> bb5;
16+
}
17+
18+
bb2: {
19+
_0 = const 456_u32;
20+
goto -> bb5;
21+
}
22+
23+
bb3: {
24+
_0 = const 789_u32;
25+
goto -> bb5;
26+
}
27+
28+
bb4: {
29+
_0 = const 0_u32;
30+
goto -> bb5;
31+
}
32+
33+
bb5: {
34+
StorageDead(_1);
35+
return;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// skip-filecheck
2+
//@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
3+
4+
#![crate_type = "lib"]
5+
6+
pub trait TraitWithBool {
7+
const FLAG: bool;
8+
}
9+
10+
// EMIT_MIR if_associated_const.check_bool.PreCodegen.after.mir
11+
pub fn check_bool<T: TraitWithBool>() -> u32 {
12+
if T::FLAG { 123 } else { 456 }
13+
}
14+
15+
pub trait TraitWithInt {
16+
const VALUE: i32;
17+
}
18+
19+
// EMIT_MIR if_associated_const.check_int.PreCodegen.after.mir
20+
pub fn check_int<T: TraitWithInt>() -> u32 {
21+
match T::VALUE {
22+
1 => 123,
23+
2 => 456,
24+
3 => 789,
25+
_ => 0,
26+
}
27+
}

0 commit comments

Comments
 (0)