about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-12-09 17:40:54 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-12-09 18:45:01 +0000
commit7c9a85bc43810bfd8b1b9657f24b5292098a49fa (patch)
tree1ac4ea15ab996f53f49256db2de6f4e3056de424
parent34e654cd7b9f347caf7d2a4726a3f632af533ea4 (diff)
downloadrust-7c9a85bc43810bfd8b1b9657f24b5292098a49fa.tar.gz
rust-7c9a85bc43810bfd8b1b9657f24b5292098a49fa.zip
fix: Don't show duplicated adjustment hints for blocks, ifs and matches
-rw-r--r--crates/ide/src/inlay_hints.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 37384c4e7e0..08ce7be1811 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -638,8 +638,12 @@ fn adjustment_hints(
         return None;
     }
 
-    if let ast::Expr::ParenExpr(_) = expr {
-        // These inherit from the inner expression which would result in duplicate hints
+    // These inherit from the inner expression which would result in duplicate hints
+    if let ast::Expr::ParenExpr(_)
+    | ast::Expr::IfExpr(_)
+    | ast::Expr::BlockExpr(_)
+    | ast::Expr::MatchExpr(_) = expr
+    {
         return None;
     }
 
@@ -3083,6 +3087,33 @@ fn main() {
    //^^^^^^^^^^^&
    //^^^^^^^^^^^*
     (&mut Struct).by_ref_mut();
+
+    // Check that block-like expressions don't duplicate hints
+    let _: &mut [u32] = (&mut []);
+                       //^^^^^^^<unsize>
+                       //^^^^^^^&mut $
+                       //^^^^^^^*
+    let _: &mut [u32] = { &mut [] };
+                        //^^^^^^^<unsize>
+                        //^^^^^^^&mut $
+                        //^^^^^^^*
+    let _: &mut [u32] = unsafe { &mut [] };
+                               //^^^^^^^<unsize>
+                               //^^^^^^^&mut $
+                               //^^^^^^^*
+    let _: &mut [u32] = if true {
+        &mut []
+      //^^^^^^^<unsize>
+      //^^^^^^^&mut $
+      //^^^^^^^*
+    } else {
+        loop {}
+      //^^^^^^^<never-to-any>
+    };
+    let _: &mut [u32] = match () { () => &mut [] }
+                                       //^^^^^^^<unsize>
+                                       //^^^^^^^&mut $
+                                       //^^^^^^^*
 }
 
 #[derive(Copy, Clone)]
@@ -3092,6 +3123,8 @@ impl Struct {
     fn by_ref(&self) {}
     fn by_ref_mut(&mut self) {}
 }
+trait Trait {}
+impl Trait for Struct {}
 "#,
         )
     }