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 e17ca31 commit d7fa8ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
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: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`.

0 comments on commit d7fa8ee

Please sign in to comment.