Confusing error when impl is available only on RefCell contents #76095
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Some Rust (playground):
yields an error about no method
do_work
being found:where
do_work
does exist, but on a different type. Specifically,WorkDoer<'_, i32>
.In the above example,
WorkDoer
should be made from a borrow of theRefCell
, likeWorkDoer { f: &*f.borrow() }
, which rustc is entirely happy to build. It would be fantastic if rustc could suggest that theborrow
would make ado_work
available.Related messages
There's (what I think to be) a similar variation of this with a more generic
impl
:yielding a more informative error:
but if the constraints become much more complex than
I: std::ops::Add
it can be very confusing to read through mismatched types only to realize you've forgotten to borrow theRefCell
.If
rustc
could observe that the inner type satisfies the constraints and makesdo_work
available, then suggest that change, it'd be kind of incredibly good and cool.(this is a minimization of https://twitter.com/iximeow/status/1297651292148359170 which @estebank also asked me to file an issue about :) the aforementioned "try borrowing the RefCell contents" suggestion would be very handy here.)
The text was updated successfully, but these errors were encountered: