Skip to content

Commit 3fa1cdf

Browse files
authored
Auto merge of #34679 - eddyb:mir-nested-pairs, r=dotdash
Handle nested pairs in MIR trans. Found while trying to compile the latest Servo master. cc @shinglyu
2 parents 9b4e2a5 + fe5ce97 commit 3fa1cdf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/librustc_trans/mir/operand.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
197197
(OperandValue::Pair(a, b),
198198
&mir::ProjectionElem::Field(ref f, ty)) => {
199199
let llval = [a, b][f.index()];
200-
return OperandRef {
200+
let op = OperandRef {
201201
val: OperandValue::Immediate(llval),
202202
ty: bcx.monomorphize(&ty)
203203
};
204+
205+
// Handle nested pairs.
206+
return op.unpack_if_pair(bcx);
204207
}
205208
_ => {}
206209
}

src/test/run-pass/mir_trans_calls.rs

+8
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ fn test_fn_ignored_pair_named() -> (Foo, Foo) {
171171
id(ignored_pair_named())
172172
}
173173

174+
#[rustc_mir]
175+
fn test_fn_nested_pair(x: &((f32, f32), u32)) -> (f32, f32) {
176+
let y = *x;
177+
let z = y.0;
178+
(z.0, z.1)
179+
}
180+
174181
fn main() {
175182
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
176183
assert_eq!(test2(98), 98);
@@ -196,4 +203,5 @@ fn main() {
196203

197204
assert_eq!(test_fn_ignored_pair_0(), ());
198205
assert_eq!(test_fn_ignored_pair_named(), (Foo, Foo));
206+
assert_eq!(test_fn_nested_pair(&((1.0, 2.0), 0)), (1.0, 2.0));
199207
}

0 commit comments

Comments
 (0)