-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Accessing fields through a Deref
impl leads to confusing error messages
#81365
Comments
@rustbot claim |
@Aaron1011 How can I check if a |
@1000teslas: You should be able to adapt this code: rust/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs Lines 798 to 893 in 0677d97
and re-use the
|
@Aaron1011 It doesn't look like |
The following code:
causes the following error message:
This error is caused by the fact that
&self.target_field
does through theDeref
impl onContainer
. As a result,&self
is borrowed, not just the desired field. Changing this line tolet first = &self.target.target_field
makes the code compile.However, the error message doesn't explain any of this. It claims that the usage of
self
is a borrow ofself.container_field
, without noting that this is due to theDeref
impl.We should do something similar to #75304 for borrows, and make it clear when lifetimes are being affected by implicit
Deref
calls.The text was updated successfully, but these errors were encountered: