mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Don't highlight let expressions as having type bool
This commit is contained in:
@@ -792,7 +792,9 @@ fn annotate_expected_due_to_let_ty(
|
||||
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(_, lhs, rhs), .. }),
|
||||
Some(TypeError::Sorts(ExpectedFound { expected, .. })),
|
||||
) if rhs.hir_id == expr.hir_id
|
||||
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected) =>
|
||||
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected)
|
||||
// let expressions being marked as `bool` is confusing (see issue #147665)
|
||||
&& !matches!(lhs.kind, hir::ExprKind::Let(..)) =>
|
||||
{
|
||||
err.span_label(lhs.span, format!("expected because this is `{expected}`"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Shouldn't highlight `let x = 1` as having type bool.
|
||||
//@ edition:2024
|
||||
|
||||
fn main() {
|
||||
if let x = 1 && 2 {}
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/let-chain-type-issue-147665.rs:5:21
|
||||
|
|
||||
LL | if let x = 1 && 2 {}
|
||||
| ^ expected `bool`, found integer
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Reference in New Issue
Block a user