about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
diff options
context:
space:
mode:
authorMartin Nordholts <martin.nordholts@codetale.se>2024-12-16 20:39:31 +0100
committerMartin Nordholts <martin.nordholts@codetale.se>2024-12-16 20:44:23 +0100
commit70a0dc1f7e964e249c4bc7c08bfeb0e96ba5deb7 (patch)
treedb0baf68f537186cace19617c72b87cf6156c7fc /compiler/rustc_borrowck/src
parent47b559d00e8723b407dd44b0d1e004bd43bab8c8 (diff)
downloadrust-70a0dc1f7e964e249c4bc7c08bfeb0e96ba5deb7.tar.gz
rust-70a0dc1f7e964e249c4bc7c08bfeb0e96ba5deb7.zip
rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable
Diffstat (limited to 'compiler/rustc_borrowck/src')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 73b76cd16d1..4938875f7c4 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -1478,11 +1478,22 @@ fn suggest_ampmut<'tcx>(
         && let Ok(rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span)
         && let Some(rhs_str_no_amp) = rhs_str.strip_prefix('&')
     {
-        let is_raw_ref = rhs_str_no_amp.trim_start().starts_with("raw ");
-        // We don't support raw refs yet
-        if is_raw_ref {
-            return None;
+        // Suggest changing `&raw const` to `&raw mut` if applicable.
+        if rhs_str_no_amp.trim_start().strip_prefix("raw const").is_some() {
+            let const_idx = rhs_str.find("const").unwrap() as u32;
+            let const_span = rhs_span
+                .with_lo(rhs_span.lo() + BytePos(const_idx))
+                .with_hi(rhs_span.lo() + BytePos(const_idx + "const".len() as u32));
+
+            return Some(AmpMutSugg {
+                has_sugg: true,
+                span: const_span,
+                suggestion: "mut".to_owned(),
+                additional: None,
+            });
         }
+
+        // Figure out if rhs already is `&mut`.
         let is_mut = if let Some(rest) = rhs_str_no_amp.trim_start().strip_prefix("mut") {
             match rest.chars().next() {
                 // e.g. `&mut x`