Skip to content

Commit

Permalink
Handle nested pairs in MIR trans.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jul 6, 2016
1 parent 4738076 commit fe5ce97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustc_trans/mir/operand.rs
Expand Up @@ -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);
}
_ => {}
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-pass/mir_trans_calls.rs
Expand Up @@ -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);
Expand All @@ -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));
}

0 comments on commit fe5ce97

Please sign in to comment.