Rollup merge of #88451 - theo-lw:issue-87771, r=jackh726
Fix an ICE caused by type mismatch errors being ignored
This PR fixes #87771. It turns out that the check on `compiler/rustc_typeck/src/check/demand.rs:148` leads to the ICE. I removed it because the early return in [`check_expr_assign`](dec7fc3ced/compiler/rustc_typeck/src/check/expr.rs (L928)
) already prevents unnecessary error messages from the call to `check_expr_coercable_to_type`.
This commit is contained in:
commit
a2c6075dff
@ -1484,21 +1484,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());
|
||||
}
|
||||
|
@ -145,12 +145,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let expr_ty = self.resolve_vars_with_obligations(checked_ty);
|
||||
let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e);
|
||||
|
||||
if self.is_assign_to_bool(expr, expected) {
|
||||
// Error reported in `check_assign` so avoid emitting error again.
|
||||
err.delay_as_bug();
|
||||
return (expected, None);
|
||||
}
|
||||
|
||||
self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr);
|
||||
|
||||
(expected, Some(err))
|
||||
@ -172,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(
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
let mut a;
|
||||
a = a = true; //~ ERROR mismatched types
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-87771-ice-assign-assign-to-bool.rs:3:9
|
||||
|
|
||||
LL | a = a = true;
|
||||
| ^^^^^^^^ expected `bool`, found `()`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
x
Reference in New Issue
Block a user