Closed
Description
If I try to assign to a value named read through a raw pointer, I get a particularly bad error message
struct Foo { read: i32 }
fn blah(x: *mut Foo) {
x.read = 4;
}
error[E0615]: attempted to take value of method `read` on type `*mut Foo`
--> src/lib.rs:4:7
|
4 | x.read = 4;
| ^^^^ method, not a field
|
= help: methods are immutable and cannot be assigned to
For more information about this error, try `rustc --explain E0615`.
error: could not compile `playground` due to previous error
I think this happens because it finds core::ptr::read
's method version on *mut T
. It would be nice if we suggested1 something like (*x).read
instead.
Footnotes
-
I guess theres a bit of trickery here since... well, technically for non-copy thats being initialized for the first time, the right thing would be
addr_of_mut!((*x).read).write(val)
... So maybe a fix shouldnt be offered, just a better diagnostic. ↩