diff options
| author | Martin Nordholts <martin.nordholts@codetale.se> | 2024-12-13 06:44:52 +0100 |
|---|---|---|
| committer | Martin Nordholts <martin.nordholts@codetale.se> | 2024-12-13 16:32:23 +0100 |
| commit | d7fa8ee6802a2c1121dca0925d3db143dd1a793c (patch) | |
| tree | a99b47ec848f3a6da726dc4c4bb4282ff727aa4f | |
| parent | e17ca31b22f26209bbdf28a95e045aa0da337733 (diff) | |
| download | rust-d7fa8ee6802a2c1121dca0925d3db143dd1a793c.tar.gz rust-d7fa8ee6802a2c1121dca0925d3db143dd1a793c.zip | |
Add regression test for issue 127562
The test fails in this commit. The next commit fixes it.
| -rw-r--r-- | tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs | 8 | ||||
| -rw-r--r-- | tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs new file mode 100644 index 00000000000..5425e571af0 --- /dev/null +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs @@ -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 +} diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr new file mode 100644 index 00000000000..0da5d15cf7f --- /dev/null +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr @@ -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`. |
