Skip to content

Commit a2c6075

Browse files
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`](https://github.com/theo-lw/rust/blob/dec7fc3ced5bc3c18d0e5d29921d087f93189cb8/compiler/rustc_typeck/src/check/expr.rs#L928) already prevents unnecessary error messages from the call to `check_expr_coercable_to_type`.
2 parents ca8a108 + 09d55d5 commit a2c6075

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

compiler/rustc_typeck/src/check/coercion.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -1484,21 +1484,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14841484
fcx.emit_coerce_suggestions(&mut err, expr, found, expected, None);
14851485
}
14861486

1487-
// Error possibly reported in `check_assign` so avoid emitting error again.
1488-
let assign_to_bool = expression
1489-
// #67273: Use initial expected type as opposed to `expected`.
1490-
// Otherwise we end up using prior coercions in e.g. a `match` expression:
1491-
// ```
1492-
// match i {
1493-
// 0 => true, // Because of this...
1494-
// 1 => i = 1, // ...`expected == bool` now, but not when checking `i = 1`.
1495-
// _ => (),
1496-
// };
1497-
// ```
1498-
.filter(|e| fcx.is_assign_to_bool(e, self.expected_ty()))
1499-
.is_some();
1500-
1501-
err.emit_unless(assign_to_bool || unsized_return);
1487+
err.emit_unless(unsized_return);
15021488

15031489
self.final_ty = Some(fcx.tcx.ty_error());
15041490
}

compiler/rustc_typeck/src/check/demand.rs

-14
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
145145
let expr_ty = self.resolve_vars_with_obligations(checked_ty);
146146
let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e);
147147

148-
if self.is_assign_to_bool(expr, expected) {
149-
// Error reported in `check_assign` so avoid emitting error again.
150-
err.delay_as_bug();
151-
return (expected, None);
152-
}
153-
154148
self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr);
155149

156150
(expected, Some(err))
@@ -172,14 +166,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172166
}
173167
}
174168

175-
/// Returns whether the expected type is `bool` and the expression is `x = y`.
176-
pub fn is_assign_to_bool(&self, expr: &hir::Expr<'_>, expected: Ty<'tcx>) -> bool {
177-
if let hir::ExprKind::Assign(..) = expr.kind {
178-
return expected == self.tcx.types.bool;
179-
}
180-
false
181-
}
182-
183169
/// If the expected type is an enum (Issue #55250) with any variants whose
184170
/// sole field is of the found type, suggest such variants. (Issue #42764)
185171
fn suggest_compatible_variants(

compiler/rustc_typeck/src/check/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9292
let expr = expr.peel_drop_temps();
9393
self.suggest_deref_ref_or_into(&mut err, expr, expected_ty, ty, None);
9494
extend_err(&mut err);
95-
// Error possibly reported in `check_assign` so avoid emitting error again.
96-
err.emit_unless(self.is_assign_to_bool(expr, expected_ty));
95+
err.emit();
9796
}
9897
ty
9998
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let mut a;
3+
a = a = true; //~ ERROR mismatched types
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-87771-ice-assign-assign-to-bool.rs:3:9
3+
|
4+
LL | a = a = true;
5+
| ^^^^^^^^ expected `bool`, found `()`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)