Skip to content

Diagnostics differ between regular execution and ui tests #131782

Open
@RalfJung

Description

@RalfJung

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

No one assigned

    Labels

    A-compiletestArea: The compiletest test runnerA-diagnosticsArea: Messages for errors, warnings, and lintsD-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions