Open
Description
Consider this example:
fn main() {
let val = 2;
let ptr = std::ptr::addr_of!(val);
unsafe { *ptr = 3; }
}
On the playground and when I run it locally, this produces:
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> src/main.rs:6:14
|
6 | 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
--> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:2207:6
|
22| &mut raw const $place
| +++
However, when I make this a ui test, I get different output:
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> /home/r/src/rust/rustc.2/tests/ui/mytest.rs:5:14
|
LL | unsafe { *ptr = 3; }
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
help: consider specifying this binding's type
|
LL | let ptr: *mut i32 = std::ptr::addr_of!(val);
| ++++++++++
That's... not great? We're supposed to test what users see, and something seems to be going wrong.
Cc @rust-lang/wg-diagnostics
Metadata
Metadata
Assignees
Labels
Area: The compiletest test runnerArea: Messages for errors, warnings, and lintsDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Backlog