Add parentheses for binding mode hints when they attach to an Or-pattern

This commit is contained in:
Lukas Wirth 2022-12-16 20:52:31 +01:00
parent 632f804797
commit b6c2bb21ab
2 changed files with 40 additions and 12 deletions

View file

@ -65,10 +65,11 @@ pub enum InlayKind {
ClosureReturnTypeHint,
GenericParamListHint,
AdjustmentHint,
AdjustmentHintClosingParenthesis,
LifetimeHint,
ParameterHint,
TypeHint,
OpeningParenthesis,
ClosingParenthesis,
}
#[derive(Debug)]
@ -671,7 +672,7 @@ fn adjustment_hints(
if needs_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::AdjustmentHint,
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
@ -716,7 +717,7 @@ fn adjustment_hints(
if needs_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::AdjustmentHintClosingParenthesis,
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
@ -880,6 +881,20 @@ fn binding_mode_hints(
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
});
}
ast::Pat::OrPat(pat) => {
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
}
_ => (),
}
@ -2951,9 +2966,18 @@ fn __(
(x,) => ()
}
match &(0,) {
(x,) => ()
//^^^^ &
(x,) | (x,) => (),
//^^^^^^^^^^^&
//^ ref
//^ ref
//^^^^^^^^^^^(
//^^^^^^^^^^^)
((x,) | (x,)) => (),
//^^^^^^^^^^^&
//^ ref
//^ ref
//^^^^^^^^^^^(
//^^^^^^^^^^^)
}
match &mut (0,) {
(x,) => ()