Diagnostics differ between regular execution and ui tests · Issue #131782 · rust-lang/rust (original) (raw)

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