Closed
Description
Code
fn main() {
let val = 2;
let ptr = &raw const val;
unsafe { *ptr = 3; }
}
Current output
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> src/main.rs:4:14
|
4 | unsafe { *ptr = 3; }
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
For more information about this error, try `rustc --explain E0594`.
Desired output
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> src/main.rs:4:14
|
4 | unsafe { *ptr = 3; }
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
help: consider changing this to be a mutable pointer
|
3 | let ptr = &raw mut val;
| ~~~
For more information about this error, try `rustc --explain E0594`.
Rationale and extra context
The current error message does not include a suggestion for how to fix it.
Other cases
No response
Rust Version
1.85.0-nightly (2024-12-14 0aeaa5eb22180fdf12a8)
Anything else?
EDIT 1: updated since addr_of!
and addr_of_mut!
diagnostics are not incorrect anymore due to #127675
EDIT 2: updated as #134224 removed the invalid suggestion