Don't highlight let expressions as having type bool
This commit is contained in:
parent
28d0a4a205
commit
984542c4e2
3 changed files with 19 additions and 1 deletions
|
|
@ -792,7 +792,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
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}`"));
|
||||
}
|
||||
|
|
|
|||
7
tests/ui/binop/let-chain-type-issue-147665.rs
Normal file
7
tests/ui/binop/let-chain-type-issue-147665.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
9
tests/ui/binop/let-chain-type-issue-147665.stderr
Normal file
9
tests/ui/binop/let-chain-type-issue-147665.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue