Skip to content

Commit

Permalink
Add regression test for issue 127562
Browse files Browse the repository at this point in the history
The test fails in this commit. The next commit fixes it.
  • Loading branch information
Enselic committed Dec 13, 2024
1 parent 0b6e7ff commit de19608
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
let val = 2;
let ptr = &raw const val;
unsafe { *ptr = 3; } //~ ERROR cannot assign to `*ptr`, which is behind a `*const` pointer
}
Original file line number Diff line number Diff line change
@@ -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:4: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`.

0 comments on commit de19608

Please sign in to comment.