about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-10-23 10:24:58 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-10-23 10:24:58 +0200
commit4fdc63ce384ff42a8f3b12e6a93891bea3c8ffd1 (patch)
tree061b1aa1cae1fea51cdd60f76db9c5a6034ead3e
parent41fc1fbaabee63a7db556b2f998e79fd862cbd57 (diff)
downloadrust-4fdc63ce384ff42a8f3b12e6a93891bea3c8ffd1.tar.gz
rust-4fdc63ce384ff42a8f3b12e6a93891bea3c8ffd1.zip
Don't emit edits for postfix adjustment hints
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs
index 8f239f6029b..0e0d50b1f35 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs
@@ -104,6 +104,7 @@ pub(super) fn hints(
     };
     let iter: &mut dyn Iterator<Item = _> = iter.as_mut().either(|it| it as _, |it| it as _);
 
+    let mut allow_edit = !postfix;
     for Adjustment { source, target, kind } in iter {
         if source == target {
             cov_mark::hit!(same_type_adjustment);
@@ -113,6 +114,7 @@ pub(super) fn hints(
         // FIXME: Add some nicer tooltips to each of these
         let (text, coercion) = match kind {
             Adjust::NeverToAny if config.adjustment_hints == AdjustmentHints::Always => {
+                allow_edit = false;
                 ("<never-to-any>", "never to any")
             }
             Adjust::Deref(None) => ("*", "dereference"),
@@ -133,6 +135,7 @@ pub(super) fn hints(
             // some of these could be represented via `as` casts, but that's not too nice and
             // handling everything as a prefix expr makes the `(` and `)` insertion easier
             Adjust::Pointer(cast) if config.adjustment_hints == AdjustmentHints::Always => {
+                allow_edit = false;
                 match cast {
                     PointerCast::ReifyFnPointer => {
                         ("<fn-item-to-fn-pointer>", "fn item to fn pointer")
@@ -179,30 +182,32 @@ pub(super) fn hints(
     if pre.is_none() && post.is_none() {
         return None;
     }
-    let edit = {
-        let mut b = TextEditBuilder::default();
-        if let Some(pre) = &pre {
-            b.insert(
-                pre.range.start(),
-                pre.label.parts.iter().map(|part| &*part.text).collect::<String>(),
-            );
-        }
-        if let Some(post) = &post {
-            b.insert(
-                post.range.end(),
-                post.label.parts.iter().map(|part| &*part.text).collect::<String>(),
-            );
-        }
-        b.finish()
-    };
-    match (&mut pre, &mut post) {
-        (Some(pre), Some(post)) => {
-            pre.text_edit = Some(edit.clone());
-            post.text_edit = Some(edit);
+    if allow_edit {
+        let edit = {
+            let mut b = TextEditBuilder::default();
+            if let Some(pre) = &pre {
+                b.insert(
+                    pre.range.start(),
+                    pre.label.parts.iter().map(|part| &*part.text).collect::<String>(),
+                );
+            }
+            if let Some(post) = &post {
+                b.insert(
+                    post.range.end(),
+                    post.label.parts.iter().map(|part| &*part.text).collect::<String>(),
+                );
+            }
+            b.finish()
+        };
+        match (&mut pre, &mut post) {
+            (Some(pre), Some(post)) => {
+                pre.text_edit = Some(edit.clone());
+                post.text_edit = Some(edit);
+            }
+            (Some(pre), None) => pre.text_edit = Some(edit),
+            (None, Some(post)) => post.text_edit = Some(edit),
+            (None, None) => (),
         }
-        (Some(pre), None) => pre.text_edit = Some(edit),
-        (None, Some(post)) => post.text_edit = Some(edit),
-        (None, None) => (),
     }
     acc.extend(pre);
     acc.extend(post);