Skip to content

Commit

Permalink
Remove special checks to is_assign_to_bool
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-lw committed Sep 17, 2021
1 parent dec7fc3 commit 09d55d5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 25 deletions.
16 changes: 1 addition & 15 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,21 +1494,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
fcx.emit_coerce_suggestions(&mut err, expr, found, expected, None);
}

// Error possibly reported in `check_assign` so avoid emitting error again.
let assign_to_bool = expression
// #67273: Use initial expected type as opposed to `expected`.
// Otherwise we end up using prior coercions in e.g. a `match` expression:
// ```
// match i {
// 0 => true, // Because of this...
// 1 => i = 1, // ...`expected == bool` now, but not when checking `i = 1`.
// _ => (),
// };
// ```
.filter(|e| fcx.is_assign_to_bool(e, self.expected_ty()))
.is_some();

err.emit_unless(assign_to_bool || unsized_return);
err.emit_unless(unsized_return);

self.final_ty = Some(fcx.tcx.ty_error());
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

/// Returns whether the expected type is `bool` and the expression is `x = y`.
pub fn is_assign_to_bool(&self, expr: &hir::Expr<'_>, expected: Ty<'tcx>) -> bool {
if let hir::ExprKind::Assign(..) = expr.kind {
return expected == self.tcx.types.bool;
}
false
}

/// If the expected type is an enum (Issue #55250) with any variants whose
/// sole field is of the found type, suggest such variants. (Issue #42764)
fn suggest_compatible_variants(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let expr = expr.peel_drop_temps();
self.suggest_deref_ref_or_into(&mut err, expr, expected_ty, ty, None);
extend_err(&mut err);
// Error possibly reported in `check_assign` so avoid emitting error again.
err.emit_unless(self.is_assign_to_bool(expr, expected_ty));
err.emit();
}
ty
}
Expand Down

0 comments on commit 09d55d5

Please sign in to comment.