Skip to content

Commit d7fa8ee

Browse files
committed
Add regression test for issue 127562
The test fails in this commit. The next commit fixes it.
1 parent e17ca31 commit d7fa8ee

2 files changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! Regression test for invalid suggestion for `&raw const expr` reported in
2+
//! <https://github.com/rust-lang/rust/issues/127562>.
3+
4+
fn main() {
5+
let val = 2;
6+
let ptr = &raw const val;
7+
unsafe { *ptr = 3; } //~ ERROR cannot assign to `*ptr`, which is behind a `*const` pointer
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
2+
--> $DIR/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs:7:14
3+
|
4+
LL | unsafe { *ptr = 3; }
5+
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable pointer
8+
|
9+
LL | let ptr = &mut raw const val;
10+
| +++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0594`.

0 commit comments

Comments
 (0)