From fe5ce97e32726a0ef05cd30898e0d1a6b5ce20ed Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 6 Jul 2016 14:41:35 +0300 Subject: [PATCH] Handle nested pairs in MIR trans. --- src/librustc_trans/mir/operand.rs | 5 ++++- src/test/run-pass/mir_trans_calls.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs index 446ac91b1f580..270033be9375c 100644 --- a/src/librustc_trans/mir/operand.rs +++ b/src/librustc_trans/mir/operand.rs @@ -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); } _ => {} } diff --git a/src/test/run-pass/mir_trans_calls.rs b/src/test/run-pass/mir_trans_calls.rs index 2371909b31b77..ca3294a87adbb 100644 --- a/src/test/run-pass/mir_trans_calls.rs +++ b/src/test/run-pass/mir_trans_calls.rs @@ -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)); }