suggest == to the first expr which has ExprKind::Assign

This commit is contained in:
Takayuki Maeda 2022-10-07 11:37:33 +09:00
parent 0ca356586f
commit 57d0278d5c
3 changed files with 36 additions and 1 deletions

View File

@ -1051,8 +1051,20 @@ fn check_expr_assign(
rhs_expr,
) = lhs.kind
{
// if x == 1 && y == 2 { .. }
// +
let actual_lhs_ty = self.check_expr(&rhs_expr);
(Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty))
} else if let ExprKind::Binary(
Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
lhs_expr,
_,
) = rhs.kind
{
// if x == 1 && y == 2 { .. }
// +
let actual_rhs_ty = self.check_expr(&lhs_expr);
(Applicability::MaybeIncorrect, self.can_coerce(actual_rhs_ty, lhs_ty))
} else {
(Applicability::MaybeIncorrect, false)
};

View File

@ -53,4 +53,10 @@ fn main() {
//~| ERROR mismatched types
println!("{}", x);
}
if x = 1 && x == 1 {
//~^ ERROR mismatched types
//~| ERROR mismatched types
println!("{}", x);
}
}

View File

@ -104,6 +104,23 @@ help: you might have meant to compare for equality
LL | if x == x && x == x && x == x {
| +
error: aborting due to 11 previous errors
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:57:12
|
LL | if x = 1 && x == 1 {
| ^ expected `bool`, found integer
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:57:8
|
LL | if x = 1 && x == 1 {
| ^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: you might have meant to compare for equality
|
LL | if x == 1 && x == 1 {
| +
error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0308`.