Suboptimal diagnostic E0599 on impl AsRef<T>
#140178
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
I was helping someone else new to Rust, and I suggested that they use
Path::join()
to append to a path. They initially tried doing that, but then it didn't work because they had the code like the one in the snippet andimpl AsRef<Path>
doesn't have a.join()
method. Iteratively trying things and fixing them on their own, with hints from the rust compiler, they eventually landed on this worse code that does compile:I think they would have found their way to the correct solution if there was any sort of hint that the problem was that they needed to add a
.as_ref()
call.More generally, I think this would be good for any
impl AsRef<T>
, if someone tries to use a method/field onT
itself (maybe excluding cases where you either haveimpl AsRef<T> + AsRef<U>
orimpl<U: AsRef<T>> SomeTrait for U
, I think these diagnostics might not be as helpful in edge-cases like those).Other cases
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: