Skip to content
Snippets Groups Projects
Commit f2962eab authored by David Renshaw's avatar David Renshaw
Browse files

simplify argument unpacking logic

parent 8eddf6ff
No related branches found
No related tags found
No related merge requests found
......@@ -439,29 +439,21 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
Value::ByVal(PrimVal::Undef) => {}
other => {
let mut layout = layout;
let mut skip_arg_locals = true;
'outer: loop {
for i in 0..layout.fields.count() {
// There can be at most one element in the tuple with nonzero size.
let mut wrote_arg = false;
for (i, arg_local) in arg_locals.enumerate() {
let field = layout.field(&self, i)?;
if layout.fields.offset(i).bytes() == 0 && layout.size == field.size {
layout = field;
skip_arg_locals = false;
continue 'outer;
} else if skip_arg_locals {
arg_locals.next().unwrap();
if layout.size == field.size {
let dest =
self.eval_lvalue(&mir::Place::Local(arg_local))?;
self.write_value(ValTy { value: other, ty: field.ty }, dest)?;
wrote_arg = true;
break;
}
}
break;
if !wrote_arg {
bug!("failed to unpack arguments from tuple {:?}", other)
}
let dest = self.eval_lvalue(&mir::Place::Local(
arg_locals.next().unwrap(),
))?;
let valty = ValTy {
value: other,
ty: layout.ty,
};
self.write_value(valty, dest)?;
}
}
} else {
......
......@@ -8,5 +8,8 @@ pub fn main() {
let h = |(), (), x: &u8| { 10u8 == *x };
h((), (), &1u8);
let h2 = |(), (), x: ((), &u8)| { 10u8 == *x.1 };
h2((), (), ((), &1u8));
[1, 2, 3u8].into_iter().any(|elt| 10 == *elt);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment