about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-16 20:51:20 +0000
committerbors <bors@rust-lang.org>2022-12-16 20:51:20 +0000
commit19c2ede549d9a5ec91ec2c20e2b32abd3e6566d4 (patch)
tree81708093c4d0fec1a50fbd98089303b8fe48774f
parent8f6d0cd1b00794bfb4e6047de98c2747807c6492 (diff)
parentba3e3282da0a6500a2a8945a664631fbd9463c64 (diff)
downloadrust-19c2ede549d9a5ec91ec2c20e2b32abd3e6566d4.tar.gz
rust-19c2ede549d9a5ec91ec2c20e2b32abd3e6566d4.zip
Auto merge of #13784 - Veykril:bm-hints, r=Veykril
Deduplicate inserted parentheses in binding mode hints
-rw-r--r--crates/ide/src/inlay_hints.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index b5b4d6ca64f..66a40627dc4 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -850,7 +850,18 @@ fn binding_mode_hints(
         return None;
     }
 
-    let range = pat.syntax().text_range();
+    let outer_paren_pat = pat
+        .syntax()
+        .ancestors()
+        .skip(1)
+        .map_while(ast::Pat::cast)
+        .map_while(|pat| match pat {
+            ast::Pat::ParenPat(pat) => Some(pat),
+            _ => None,
+        })
+        .last();
+    let range =
+        outer_paren_pat.as_ref().map_or_else(|| pat.syntax(), |it| it.syntax()).text_range();
     sema.pattern_adjustments(&pat).iter().for_each(|ty| {
         let reference = ty.is_reference();
         let mut_reference = ty.is_mutable_reference();
@@ -875,13 +886,13 @@ fn binding_mode_hints(
                 hir::BindingMode::Ref(Mutability::Shared) => "ref",
             };
             acc.push(InlayHint {
-                range,
+                range: pat.syntax().text_range(),
                 kind: InlayKind::BindingModeHint,
                 label: bm.to_string().into(),
                 tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
             });
         }
-        ast::Pat::OrPat(pat) => {
+        ast::Pat::OrPat(pat) if outer_paren_pat.is_none() => {
             acc.push(InlayHint {
                 range: pat.syntax().text_range(),
                 kind: InlayKind::OpeningParenthesis,
@@ -2973,11 +2984,9 @@ fn __(
       //^^^^^^^^^^^(
       //^^^^^^^^^^^)
         ((x,) | (x,)) => (),
-       //^^^^^^^^^^^&
+      //^^^^^^^^^^^^^&
         //^ ref
                //^ ref
-       //^^^^^^^^^^^(
-       //^^^^^^^^^^^)
     }
     match &mut (0,) {
         (x,) => ()