Skip to content

Commit 09d55d5

Browse files
committed
Remove special checks to is_assign_to_bool
1 parent dec7fc3 commit 09d55d5

File tree

3 files changed

+2
-25
lines changed

3 files changed

+2
-25
lines changed

compiler/rustc_typeck/src/check/coercion.rs

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

1497-
// Error possibly reported in `check_assign` so avoid emitting error again.
1498-
let assign_to_bool = expression
1499-
// #67273: Use initial expected type as opposed to `expected`.
1500-
// Otherwise we end up using prior coercions in e.g. a `match` expression:
1501-
// ```
1502-
// match i {
1503-
// 0 => true, // Because of this...
1504-
// 1 => i = 1, // ...`expected == bool` now, but not when checking `i = 1`.
1505-
// _ => (),
1506-
// };
1507-
// ```
1508-
.filter(|e| fcx.is_assign_to_bool(e, self.expected_ty()))
1509-
.is_some();
1510-
1511-
err.emit_unless(assign_to_bool || unsized_return);
1497+
err.emit_unless(unsized_return);
15121498

15131499
self.final_ty = Some(fcx.tcx.ty_error());
15141500
}

compiler/rustc_typeck/src/check/demand.rs

-8
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166166
}
167167
}
168168

169-
/// Returns whether the expected type is `bool` and the expression is `x = y`.
170-
pub fn is_assign_to_bool(&self, expr: &hir::Expr<'_>, expected: Ty<'tcx>) -> bool {
171-
if let hir::ExprKind::Assign(..) = expr.kind {
172-
return expected == self.tcx.types.bool;
173-
}
174-
false
175-
}
176-
177169
/// If the expected type is an enum (Issue #55250) with any variants whose
178170
/// sole field is of the found type, suggest such variants. (Issue #42764)
179171
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
}

0 commit comments

Comments
 (0)