Skip to content

Commit d92e3da

Browse files
committed
Don't highlight let expressions as having type bool
Addresses #147665
1 parent 28d0a4a commit d92e3da

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
792792
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(_, lhs, rhs), .. }),
793793
Some(TypeError::Sorts(ExpectedFound { expected, .. })),
794794
) if rhs.hir_id == expr.hir_id
795-
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected) =>
795+
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected)
796+
// let expressions being marked as `bool` is confusing (see issue #147665)
797+
&& !matches!(lhs.kind, hir::ExprKind::Let(..)) =>
796798
{
797799
err.span_label(lhs.span, format!("expected because this is `{expected}`"));
798800
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Shouldn't highlight `let x = 1` as having type bool.
2+
//@ edition:2024
3+
4+
fn main() {
5+
if let x = 1 && 2 {}
6+
//~^ ERROR mismatched types
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/let-chain-type-issue-147665.rs:5:21
3+
|
4+
LL | if let x = 1 && 2 {}
5+
| ^ expected `bool`, found integer
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)