diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 42769a863640..c67b98761aa6 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -420,13 +420,11 @@ pub fn check_match(&self, _ => result_ty }; - let mut arm_tys = Vec::new(); for (i, arm) in arms.iter().enumerate() { if let Some(ref e) = arm.guard { self.check_expr_has_type(e, tcx.types.bool); } let arm_ty = self.check_expr_with_expectation(&arm.body, expected); - arm_tys.push(arm_ty); if result_ty.references_error() || arm_ty.references_error() { result_ty = tcx.types.err; @@ -458,8 +456,7 @@ pub fn check_match(&self, // Special-case the first arm, as it has no "previous expressions". self.try_coerce(&arm.body, arm_ty, coerce_first) } else { - let prev_arms = || arms[..i].iter().map(|arm| &*arm.body) - .zip(arm_tys.iter().cloned()); + let prev_arms = || arms[..i].iter().map(|arm| &*arm.body); self.try_find_coercion_lub(origin, prev_arms, result_ty, &arm.body, arm_ty) }; diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 263a83389ea9..98a05989b140 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -664,7 +664,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self, -> RelateResult<'tcx, Ty<'tcx>> // FIXME(eddyb) use copyable iterators when that becomes ergonomic. where E: Fn() -> I, - I: IntoIterator)> { + I: IntoIterator { let prev_ty = self.resolve_type_vars_with_obligations(prev_ty); let new_ty = self.resolve_type_vars_with_obligations(new_ty); @@ -703,7 +703,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self, } // Reify both sides and return the reified fn pointer type. - for (expr, _) in exprs().into_iter().chain(Some((new, new_ty))) { + for expr in exprs().into_iter().chain(Some(new)) { // No adjustments can produce a fn item, so this should never trip. assert!(!self.tables.borrow().adjustments.contains_key(&expr.id)); self.write_adjustment(expr.id, AdjustReifyFnPointer); @@ -737,13 +737,13 @@ pub fn try_find_coercion_lub<'b, E, I>(&self, // Then try to coerce the previous expressions to the type of the new one. // This requires ensuring there are no coercions applied to *any* of the // previous expressions, other than noop reborrows (ignoring lifetimes). - for (expr, expr_ty) in exprs() { + for expr in exprs() { let noop = match self.tables.borrow().adjustments.get(&expr.id) { Some(&AdjustDerefRef(AutoDerefRef { autoderefs: 1, autoref: Some(AutoPtr(_, mutbl_adj)), unsize: None - })) => match expr_ty.sty { + })) => match self.node_ty(expr.id).sty { ty::TyRef(_, mt_orig) => { // Reborrow that we can safely ignore. mutbl_adj == mt_orig.mutbl @@ -767,9 +767,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self, } } - match self.commit_if_ok(|_| apply(&mut coerce, - &|| exprs().into_iter().map(|(e, _)| e), - prev_ty, new_ty)) { + match self.commit_if_ok(|_| apply(&mut coerce, &exprs, prev_ty, new_ty)) { Err(_) => { // Avoid giving strange errors on failed attempts. if let Some(e) = first_error { @@ -787,7 +785,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self, } Ok((ty, adjustment)) => { if !adjustment.is_identity() { - for (expr, _) in exprs() { + for expr in exprs() { let previous = self.tables.borrow().adjustments.get(&expr.id).cloned(); if let Some(AdjustNeverToAny(_)) = previous { self.write_adjustment(expr.id, AdjustNeverToAny(ty)); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b12833392135..1e57cc5d6c84 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2861,7 +2861,7 @@ fn check_then_else(&self, // Only try to coerce-unify if we have a then expression // to assign coercions to, otherwise it's () or diverging. let result = if let Some(ref then) = then_blk.expr { - let res = self.try_find_coercion_lub(origin, || Some((&**then, then_ty)), + let res = self.try_find_coercion_lub(origin, || Some(&**then), then_ty, else_expr, else_ty); // In case we did perform an adjustment, we have to update @@ -3594,18 +3594,15 @@ fn check_expr_kind(&self, let mut unified = self.next_ty_var(); let coerce_to = uty.unwrap_or(unified); - let mut arg_tys = Vec::new(); for (i, e) in args.iter().enumerate() { let e_ty = self.check_expr_with_hint(e, coerce_to); - arg_tys.push(e_ty); let origin = TypeOrigin::Misc(e.span); // Special-case the first element, as it has no "previous expressions". let result = if i == 0 { self.try_coerce(e, e_ty, coerce_to) } else { - let prev_elems = || args[..i].iter().map(|e| &**e) - .zip(arg_tys.iter().cloned()); + let prev_elems = || args[..i].iter().map(|e| &**e); self.try_find_coercion_lub(origin, prev_elems, unified, e, e_ty) };