Rollup merge of #102765 - TaKO8Ki:follow-up-to-102708, r=compiler-errors
Suggest `==` to the first expr which has `ExprKind::Assign` kind follow-up to #102708 [playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4241dc33ed8af02e1ef530d6b14903fd)
This commit is contained in:
commit
ad45dd1722
@ -1051,8 +1051,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
rhs_expr,
|
rhs_expr,
|
||||||
) = lhs.kind
|
) = lhs.kind
|
||||||
{
|
{
|
||||||
|
// if x == 1 && y == 2 { .. }
|
||||||
|
// +
|
||||||
let actual_lhs_ty = self.check_expr(&rhs_expr);
|
let actual_lhs_ty = self.check_expr(&rhs_expr);
|
||||||
(Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty))
|
(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 {
|
} else {
|
||||||
(Applicability::MaybeIncorrect, false)
|
(Applicability::MaybeIncorrect, false)
|
||||||
};
|
};
|
||||||
|
@ -53,4 +53,10 @@ fn main() {
|
|||||||
//~| ERROR mismatched types
|
//~| ERROR mismatched types
|
||||||
println!("{}", x);
|
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 {
|
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`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user