Skip to content

Commit a1e3451

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

3 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// MIR for `check_bool` after PreCodegen
2+
3+
fn check_bool() -> u32 {
4+
let mut _0: u32;
5+
6+
bb0: {
7+
switchInt(const <T as TraitWithBool>::FLAG) -> [0: bb1, otherwise: bb2];
8+
}
9+
10+
bb1: {
11+
_0 = const 456_u32;
12+
goto -> bb3;
13+
}
14+
15+
bb2: {
16+
_0 = const 123_u32;
17+
goto -> bb3;
18+
}
19+
20+
bb3: {
21+
return;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// MIR for `check_int` after PreCodegen
2+
3+
fn check_int() -> u32 {
4+
let mut _0: u32;
5+
6+
bb0: {
7+
switchInt(const <T as TraitWithInt>::VALUE) -> [1: bb1, 2: bb2, 3: bb3, otherwise: bb4];
8+
}
9+
10+
bb1: {
11+
_0 = const 123_u32;
12+
goto -> bb5;
13+
}
14+
15+
bb2: {
16+
_0 = const 456_u32;
17+
goto -> bb5;
18+
}
19+
20+
bb3: {
21+
_0 = const 789_u32;
22+
goto -> bb5;
23+
}
24+
25+
bb4: {
26+
_0 = const 0_u32;
27+
goto -> bb5;
28+
}
29+
30+
bb5: {
31+
return;
32+
}
33+
}
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)