diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3c41e4042b952..bfe92fc5be802 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2833,19 +2833,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_expr_coercable_to_type(&self, expr: &'gcx hir::Expr, expected: Ty<'tcx>) -> Ty<'tcx> { - self.check_expr_coercable_to_type_with_needs(expr, expected, Needs::None) - } - - fn check_expr_coercable_to_type_with_needs(&self, - expr: &'gcx hir::Expr, - expected: Ty<'tcx>, - needs: Needs) - -> Ty<'tcx> { - let ty = self.check_expr_with_expectation_and_needs( - expr, - ExpectHasType(expected), - needs); - // checks don't need two phase + let ty = self.check_expr_with_hint(expr, expected); self.demand_coerce(expr, ty, expected, AllowTwoPhase::No) } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index efc1e2a80cebe..4a175248d74a3 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -174,9 +174,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // trait matching creating lifetime constraints that are too strict. // E.g. adding `&'a T` and `&'b T`, given `&'x T: Add<&'x T>`, will result // in `&'a T <: &'x T` and `&'b T <: &'x T`, instead of `'a = 'b = 'x`. - let lhs_ty = self.check_expr_coercable_to_type_with_needs(lhs_expr, - self.next_ty_var(TypeVariableOrigin::MiscVariable(lhs_expr.span)), - lhs_needs); + let lhs_ty = self.check_expr_with_needs(lhs_expr, lhs_needs); + let fresh_var = self.next_ty_var(TypeVariableOrigin::MiscVariable(lhs_expr.span)); + let lhs_ty = self.demand_coerce(lhs_expr, lhs_ty, fresh_var, AllowTwoPhase::No); let lhs_ty = self.resolve_type_vars_with_obligations(lhs_ty); // NB: As we have not yet type-checked the RHS, we don't have the