Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics differ between regular execution and ui tests #131782

Open
RalfJung opened this issue Oct 16, 2024 · 3 comments
Open

Diagnostics differ between regular execution and ui tests #131782

RalfJung opened this issue Oct 16, 2024 · 3 comments
Labels
A-compiletest Area: The compiletest test runner A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 16, 2024
@compiler-errors
Copy link
Member

probably due to #105500

@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 16, 2024
@RalfJung RalfJung added the A-compiletest Area: The compiletest test runner label Nov 9, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Nov 9, 2024

Cc @jieyouxu -- should this be added to the compiletest project board?

@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

Yes, somehow I missed this one, thanks for the ping.

@jieyouxu jieyouxu added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

4 participants