-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest =
to ==
in more cases, even in the face of reference mismatch
#119328
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after fixing
@@ -1131,8 +1131,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
let mut err = self.demand_suptype_diag(expr.span, expected_ty, actual_ty).unwrap(); | |||
let lhs_ty = self.check_expr(lhs); | |||
let rhs_ty = self.check_expr(rhs); | |||
let might_coerce = |lhs: Ty<'tcx>, rhs: Ty<'tcx>| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper is named pretty vaguely -- it's not checking if lhs and rhs might coerce, it's checking if the lhs and rhs's refs can coerce.
let might_coerce = |lhs: Ty<'tcx>, rhs: Ty<'tcx>| { | |
let refs_can_coerce = |lhs: Ty<'tcx>, rhs: Ty<'tcx>| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's weird because from the user's point of view it is Ty
, but auto-deref is at play in binops (which is why I peel all refs and add one layer after).
(Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty)) | ||
( | ||
Applicability::MaybeIncorrect, | ||
self.can_coerce(rhs_ty, actual_lhs_ty) | might_coerce(rhs_ty, actual_lhs_ty), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binary ||
self.can_coerce(rhs_ty, actual_lhs_ty) | might_coerce(rhs_ty, actual_lhs_ty), | |
self.can_coerce(rhs_ty, actual_lhs_ty) || might_coerce(rhs_ty, actual_lhs_ty), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been making this mistake often lately, I wonder what's causing that 🤔
Maybe that I write alternative patterns way more often than logical ors? No idea 🤷
…atch Given `foo: &String` and `bar: str`, suggest `==` when given `if foo = bar {}`: ``` error[E0308]: mismatched types --> $DIR/assignment-expected-bool.rs:37:8 | LL | if foo = bar {} | ^^^^^^^^^ expected `bool`, found `()` | help: you might have meant to compare for equality | LL | if foo == bar {} | + ```
1eb9334
to
dc30eb1
Compare
@bors r=compiler-errors |
☀️ Test successful - checks-actions |
Finished benchmarking commit (eee93d8): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.634s -> 671.325s (0.25%) |
The perf improvement is spurious: #118431 (comment) |
Given
foo: &String
andbar: str
, suggest==
when givenif foo = bar {}
: