Misc HIR typeck type mismatch tweaks#112116
Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
ce910f8 to
89032b4
Compare
estebank
left a comment
There was a problem hiding this comment.
Can we add a check for the following?
let _: Result<&usize, _> = &Ok(42);There was a problem hiding this comment.
The expectation in the ticket was for this to suggest .as_ref(), right?
There was a problem hiding this comment.
Yes, which is why I didn't close it just yet.
tests/ui/issues/issue-100605.stderr
Outdated
There was a problem hiding this comment.
I'll see if I can add it back
There was a problem hiding this comment.
Wait, I'm not actually sure what you're talking about when looking at this now 😅
For the &Some case, we still give the right suggestion below:
help: try using `.as_ref()` to convert `&Option<String>` to `Option<&String>`
|
LL - takes_option(&res);
LL + takes_option(res.as_ref());
And for the &None case, we no longer suggest None.as_ref(), in favor of just suggesting removing the & which is far more accurate.
7a667ec to
6615862
Compare
|
@compiler-errors the tests look good, thanks for the work! I'll review the code shortly... One question though, does the code support something like this: let _: Option<&usize> = Some(1);I'd expect rustc to suggest |
@WaffleLapkin: I don't think it does. I debated adding support for autoref-ish suggestions, but that case specifically has a higher likelihood than the others to lead to later borrowck errors compared to just deref-related suggestions because it may require taking a reference to a temporary or something. |
|
Oops, correction: it does suggest let y = Some(1);
let _: Option<&usize> = y;Which says: Otherwise the compiler prefers to suggest |
tests/ui/suggestions/as-ref.stderr
Outdated
There was a problem hiding this comment.
Despite the concerns of this not being idiomatic, I'm more than ok with landing with a suggestion like this.
There was a problem hiding this comment.
Why this checks for string specifically? (and not for example for a type with as_ref with an appropriate signature or something like that)
There was a problem hiding this comment.
Because it's complicated, 🤷
I didn't implement this specific suggestion, just moved it around, and I don't really want to make it particularly more complicated 😅
There was a problem hiding this comment.
String::as_str without the closure, maybe?
There was a problem hiding this comment.
I think this applies with any number of peeled refs, so this won't work:
fn f(x: Option<&&&&String>) {
let _: Option<&str> = x;
}
|
r=me with(out) nits |
6615862 to
a918822
Compare
|
@bors r=WaffleLapkin |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (9c843d9): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @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: 649.387s -> 649.729s (0.05%) |
@rustbot label: +perf-regression-triaged |
|
Also I don't think I changed anything that isn't on the error path. |
These are all intended to improve #112104, but I couldn't get it to actually suggest adding
as_refto the LHS of the equality expr without some hacks that I may play around with some more.Each commit's title should explain what it's doing except for perhaps the last one, which addresses the bogus suggestion on #112104 itself.