Skip to content

Commit 19c2ede

Browse files
committed
Auto merge of rust-lang#13784 - Veykril:bm-hints, r=Veykril
Deduplicate inserted parentheses in binding mode hints
2 parents 8f6d0cd + ba3e328 commit 19c2ede

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crates/ide/src/inlay_hints.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,18 @@ fn binding_mode_hints(
850850
return None;
851851
}
852852

853-
let range = pat.syntax().text_range();
853+
let outer_paren_pat = pat
854+
.syntax()
855+
.ancestors()
856+
.skip(1)
857+
.map_while(ast::Pat::cast)
858+
.map_while(|pat| match pat {
859+
ast::Pat::ParenPat(pat) => Some(pat),
860+
_ => None,
861+
})
862+
.last();
863+
let range =
864+
outer_paren_pat.as_ref().map_or_else(|| pat.syntax(), |it| it.syntax()).text_range();
854865
sema.pattern_adjustments(&pat).iter().for_each(|ty| {
855866
let reference = ty.is_reference();
856867
let mut_reference = ty.is_mutable_reference();
@@ -875,13 +886,13 @@ fn binding_mode_hints(
875886
hir::BindingMode::Ref(Mutability::Shared) => "ref",
876887
};
877888
acc.push(InlayHint {
878-
range,
889+
range: pat.syntax().text_range(),
879890
kind: InlayKind::BindingModeHint,
880891
label: bm.to_string().into(),
881892
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
882893
});
883894
}
884-
ast::Pat::OrPat(pat) => {
895+
ast::Pat::OrPat(pat) if outer_paren_pat.is_none() => {
885896
acc.push(InlayHint {
886897
range: pat.syntax().text_range(),
887898
kind: InlayKind::OpeningParenthesis,
@@ -2973,11 +2984,9 @@ fn __(
29732984
//^^^^^^^^^^^(
29742985
//^^^^^^^^^^^)
29752986
((x,) | (x,)) => (),
2976-
//^^^^^^^^^^^&
2987+
//^^^^^^^^^^^^^&
29772988
//^ ref
29782989
//^ ref
2979-
//^^^^^^^^^^^(
2980-
//^^^^^^^^^^^)
29812990
}
29822991
match &mut (0,) {
29832992
(x,) => ()

0 commit comments

Comments
 (0)