From 7c8f5457d26055b26210fdd69c5ded1ecdde144a Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Sun, 28 Aug 2016 17:29:54 +0800 Subject: [PATCH] Undo unnecessary bookkeeping from last commit --- src/librustc_typeck/check/_match.rs | 5 +---- src/librustc_typeck/check/coercion.rs | 14 ++++++-------- src/librustc_typeck/check/mod.rs | 7 ++----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 42769a8636407..c67b98761aa6e 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -420,13 +420,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { _ => 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // 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 263a83389ea9d..98a05989b140d 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -664,7 +664,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { -> 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } // 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } 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 b128333921356..1e57cc5d6c847 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2861,7 +2861,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // 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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { 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) };