Suggest = to == in more cases, even in the face of reference mismatch#119328
Suggest = to == in more cases, even in the face of reference mismatch#119328bors merged 1 commit intorust-lang:masterfrom
= to == in more cases, even in the face of reference mismatch#119328Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
compiler-errors
left a comment
There was a problem hiding this comment.
r=me after fixing
| 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.
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.
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.
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.
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: &Stringandbar: str, suggest==when givenif foo = bar {}: