You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems to be slightly related to #28419 but maybe not the same as the error is a different? Feel free to close if it actually is the same.
use std::ops;structFoo(Bar);structBar;impl ops::DerefforFoo{typeTarget = Bar;fnderef(&self) -> &Bar{&self.0}}implBar{fndo_stuff(&mutself){}}fnmain(){letmut f = Foo(Bar);
f.do_stuff();}
This currently gives the following error
error[E0596]: cannot borrow data in a `&` reference as mutable
--> src/main.rs:20:5
|
20 | f.do_stuff();
| ^ cannot borrow as mutable
error: aborting due to previous error
There are multiple problems with that error message:
a) A DerefMut impl would be needed but that's not what it writes
b) It's unclear where the & reference in that line comes from (auto-deref!)
c) f itself can actually be borrowed mutable, but the error suggests that it can't and that this is the problem
Maybe there's some opportunity for generally improving error messages when auto-deref is involved, and somehow making that clear in the error message. E.g. by putting another paragraph there saying when calling do_stuff() on type Foo caused by auto-deref or similar, or maybe similar to how borrow errors are shown ("which was borrowed mutable $here") by marking in a separate message that auto-deref has happened here.
The text was updated successfully, but these errors were encountered:
This seems to be slightly related to #28419 but maybe not the same as the error is a different? Feel free to close if it actually is the same.
This currently gives the following error
There are multiple problems with that error message:
a) A
DerefMut
impl would be needed but that's not what it writesb) It's unclear where the
&
reference in that line comes from (auto-deref!)c)
f
itself can actually be borrowed mutable, but the error suggests that it can't and that this is the problemMaybe there's some opportunity for generally improving error messages when auto-deref is involved, and somehow making that clear in the error message. E.g. by putting another paragraph there saying
when calling do_stuff() on type Foo caused by auto-deref
or similar, or maybe similar to how borrow errors are shown ("which was borrowed mutable $here") by marking in a separate message that auto-deref has happened here.The text was updated successfully, but these errors were encountered: