Add regression test for issue 127562

The test fails in this commit. The next commit fixes it.
This commit is contained in:
Martin Nordholts 2024-12-13 06:44:52 +01:00
parent e17ca31b22
commit d7fa8ee680
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,8 @@
//! Regression test for invalid suggestion for `&raw const expr` reported in
//! <https://github.com/rust-lang/rust/issues/127562>.
fn main() {
let val = 2;
let ptr = &raw const val;
unsafe { *ptr = 3; } //~ ERROR cannot assign to `*ptr`, which is behind a `*const` pointer
}

View File

@ -0,0 +1,14 @@
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
--> $DIR/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs:7:14
|
LL | 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
|
LL | let ptr = &mut raw const val;
| +++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0594`.