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
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. ↩
The text was updated successfully, but these errors were encountered:
If the field isn't "shadowed" by a method name, it says something like
error[E0609]: no field `red` on type `*mut Foo`
--> src/lib.rs:4:7
|
4 | x.red = 4;
| --^^^
| |
| help: `x` is a raw pointer; try dereferencing it: `(*x).red`
If I try to assign to a value named read through a raw pointer, I get a particularly bad error message
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1a491cb65ab0afb0f69c80d92b91d7f5
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. ↩The text was updated successfully, but these errors were encountered: