diff options
| author | Martin Nordholts <martin.nordholts@codetale.se> | 2024-12-13 07:00:08 +0100 |
|---|---|---|
| committer | Martin Nordholts <martin.nordholts@codetale.se> | 2024-12-13 16:33:47 +0100 |
| commit | 2d2c6f2a80167d9f244d8c926fdf3b3aebf3f42f (patch) | |
| tree | 3f6427e6f0b51edc06ded1895ba6964ef6ddd38e | |
| parent | d7fa8ee6802a2c1121dca0925d3db143dd1a793c (diff) | |
| download | rust-2d2c6f2a80167d9f244d8c926fdf3b3aebf3f42f.tar.gz rust-2d2c6f2a80167d9f244d8c926fdf3b3aebf3f42f.zip | |
rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`
A legitimate suggestion would be to change from
&raw const val
to
&raw mut val
But until we have figured out how to make that happen we should at least
stop suggesting invalid syntax.
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs | 5 | ||||
| -rw-r--r-- | tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr | 5 |
2 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 48fc0c331b8..044a828b346 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1455,6 +1455,11 @@ fn suggest_ampmut<'tcx>( && let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) && let Some(stripped) = src.strip_prefix('&') { + let is_raw_ref = stripped.trim_start().starts_with("raw "); + // We don't support raw refs yet + if is_raw_ref { + return None; + } let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") { match rest.chars().next() { // e.g. `&mut x` 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 index 0da5d15cf7f..c27dcc19827 100644 --- 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 @@ -3,11 +3,6 @@ error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer | 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 |
