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
This commit is contained in:
bors 2016-07-08 00:41:35 -07:00 committed by GitHub
commit 3fa1cdf23c
2 changed files with 12 additions and 1 deletions

View File

@ -197,10 +197,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
(OperandValue::Pair(a, b),
&mir::ProjectionElem::Field(ref f, ty)) => {
let llval = [a, b][f.index()];
return OperandRef {
let op = OperandRef {
val: OperandValue::Immediate(llval),
ty: bcx.monomorphize(&ty)
};
// Handle nested pairs.
return op.unpack_if_pair(bcx);
}
_ => {}
}

View File

@ -171,6 +171,13 @@ fn test_fn_ignored_pair_named() -> (Foo, Foo) {
id(ignored_pair_named())
}
#[rustc_mir]
fn test_fn_nested_pair(x: &((f32, f32), u32)) -> (f32, f32) {
let y = *x;
let z = y.0;
(z.0, z.1)
}
fn main() {
assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
assert_eq!(test2(98), 98);
@ -196,4 +203,5 @@ fn main() {
assert_eq!(test_fn_ignored_pair_0(), ());
assert_eq!(test_fn_ignored_pair_named(), (Foo, Foo));
assert_eq!(test_fn_nested_pair(&((1.0, 2.0), 0)), (1.0, 2.0));
}