suggest ==
to the first expr which has ExprKind::Assign
This commit is contained in:
parent
0ca356586f
commit
57d0278d5c
@ -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)
|
||||
};
|
||||
|
@ -53,4 +53,10 @@ fn main() {
|
||||
//~| ERROR mismatched types
|
||||
println!("{}", x);
|
||||
}
|
||||
|
||||
if x = 1 && x == 1 {
|
||||
//~^ ERROR mismatched types
|
||||
//~| ERROR mismatched types
|
||||
println!("{}", x);
|
||||
}
|
||||
}
|
||||
|
@ -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`.
|
||||
|
Loading…
Reference in New Issue
Block a user