diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index 10faf307fa1bd0a91fc51ec03de214409b929caf..2177472fe9256b98b5bd9c23327c394ea01cc706 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -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() { - 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(); - } + // 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.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; } - 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)?; + if !wrote_arg { + bug!("failed to unpack arguments from tuple {:?}", other) + } } } } else { diff --git a/tests/run-pass/iter_any.rs b/tests/run-pass/iter_any.rs index b14eb074488b29244744dd496a86dff277c5955d..6753681413a58ae8ea5326457f5eb9df22bfb232 100644 --- a/tests/run-pass/iter_any.rs +++ b/tests/run-pass/iter_any.rs @@ -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); }