Skip to content

Commit

Permalink
Undo unnecessary bookkeeping from last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Sep 5, 2016
1 parent 180534f commit 7c8f545
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
};

Expand Down
14 changes: 6 additions & 8 deletions src/librustc_typeck/check/coercion.rs
Expand Up @@ -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<Item=(&'b hir::Expr, Ty<'tcx>)> {
I: IntoIterator<Item=&'b hir::Expr> {

let prev_ty = self.resolve_type_vars_with_obligations(prev_ty);
let new_ty = self.resolve_type_vars_with_obligations(new_ty);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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));
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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)
};

Expand Down

0 comments on commit 7c8f545

Please sign in to comment.