Skip to content

Commit 1b21952

Browse files
committed
Also add a MIR pre-codegen test for the derived PartialOrd::le
1 parent 30f168e commit 1b21952

File tree

2 files changed

+98
-0
lines changed

2 files changed

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

Diff for: 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)