Skip to content

Commit 9cc52bc

Browse files
committed
Also add a MIR pre-codegen test for the derived PartialOrd::le
1 parent 1c3b035 commit 9cc52bc

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// MIR for `demo_le` after PreCodegen
2+
3+
fn demo_le(_1: &MultiField, _2: &MultiField) -> bool {
4+
debug a => _1;
5+
debug b => _2;
6+
let mut _0: bool;
7+
scope 1 (inlined <MultiField as PartialOrd>::le) {
8+
let mut _11: std::option::Option<std::cmp::Ordering>;
9+
scope 2 (inlined Option::<std::cmp::Ordering>::is_some_and::<fn(std::cmp::Ordering) -> bool {std::cmp::Ordering::is_le}>) {
10+
let _12: std::cmp::Ordering;
11+
let mut _13: (std::cmp::Ordering,);
12+
scope 3 {
13+
}
14+
}
15+
scope 4 (inlined <MultiField as PartialOrd>::partial_cmp) {
16+
let mut _6: std::option::Option<std::cmp::Ordering>;
17+
let mut _7: i8;
18+
scope 5 {
19+
}
20+
scope 6 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
21+
let mut _3: char;
22+
let mut _4: char;
23+
let mut _5: std::cmp::Ordering;
24+
}
25+
scope 7 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
26+
let mut _8: i16;
27+
let mut _9: i16;
28+
let mut _10: std::cmp::Ordering;
29+
}
30+
}
31+
}
32+
33+
bb0: {
34+
StorageLive(_11);
35+
StorageLive(_5);
36+
StorageLive(_7);
37+
StorageLive(_3);
38+
_3 = copy ((*_1).0: char);
39+
StorageLive(_4);
40+
_4 = copy ((*_2).0: char);
41+
_5 = Cmp(move _3, move _4);
42+
StorageDead(_4);
43+
StorageDead(_3);
44+
_6 = Option::<std::cmp::Ordering>::Some(copy _5);
45+
_7 = discriminant(_5);
46+
switchInt(move _7) -> [0: bb1, otherwise: bb2];
47+
}
48+
49+
bb1: {
50+
StorageLive(_10);
51+
StorageLive(_8);
52+
_8 = copy ((*_1).1: i16);
53+
StorageLive(_9);
54+
_9 = copy ((*_2).1: i16);
55+
_10 = Cmp(move _8, move _9);
56+
StorageDead(_9);
57+
StorageDead(_8);
58+
_11 = Option::<std::cmp::Ordering>::Some(move _10);
59+
StorageDead(_10);
60+
StorageDead(_7);
61+
StorageDead(_5);
62+
StorageLive(_12);
63+
goto -> bb3;
64+
}
65+
66+
bb2: {
67+
_11 = copy _6;
68+
StorageDead(_7);
69+
StorageDead(_5);
70+
StorageLive(_12);
71+
goto -> bb3;
72+
}
73+
74+
bb3: {
75+
_12 = move ((_11 as Some).0: std::cmp::Ordering);
76+
StorageLive(_13);
77+
_13 = (copy _12,);
78+
_0 = <fn(std::cmp::Ordering) -> bool {std::cmp::Ordering::is_le} as FnOnce<(std::cmp::Ordering,)>>::call_once(std::cmp::Ordering::is_le, move _13) -> [return: bb4, unwind unreachable];
79+
}
80+
81+
bb4: {
82+
StorageDead(_13);
83+
StorageDead(_12);
84+
StorageDead(_11);
85+
return;
86+
}
87+
}

tests/mir-opt/pre-codegen/derived_ord.rs

+7
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66
#[derive(PartialOrd, PartialEq)]
77
pub struct MultiField(char, i16);
88

9+
// Because this isn't derived by the impl, it's not on the `{impl#0}-partial_cmp`,
10+
// and thus we need to call it to see what the inlined generic one produces.
11+
pub fn demo_le(a: &MultiField, b: &MultiField) -> bool {
12+
*a <= *b
13+
}
14+
915
// EMIT_MIR derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir
16+
// EMIT_MIR derived_ord.demo_le.PreCodegen.after.mir

0 commit comments

Comments
 (0)