Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints/adjustment.rs')
-rw-r--r--crates/ide/src/inlay_hints/adjustment.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/ide/src/inlay_hints/adjustment.rs b/crates/ide/src/inlay_hints/adjustment.rs
index d3b95750f7..40156ace26 100644
--- a/crates/ide/src/inlay_hints/adjustment.rs
+++ b/crates/ide/src/inlay_hints/adjustment.rs
@@ -260,7 +260,7 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool,
if postfix {
// postfix ops have higher precedence than any other operator, so we need to wrap
// any inner expression that is below (except for jumps if they don't have a value)
- let needs_inner_parens = prec < ExprPrecedence::Unambiguous && {
+ let needs_inner_parens = prec < ExprPrecedence::Postfix && {
prec != ExprPrecedence::Jump || !expr.is_ret_like_with_no_value()
};
// given we are the higher precedence, no parent expression will have stronger requirements
@@ -276,9 +276,12 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool,
// if we are already wrapped, great, no need to wrap again
.filter(|it| !matches!(it, ast::Expr::ParenExpr(_)))
.map(|it| it.precedence());
+
// if we have no parent, we don't need outer parens to disambiguate
// otherwise anything with higher precedence than what we insert needs to wrap us
- let needs_outer_parens = parent.is_some_and(|prec| prec > ExprPrecedence::Prefix);
+ // that means only postfix ops
+ let needs_outer_parens =
+ parent.is_some_and(|parent_prec| parent_prec == ExprPrecedence::Postfix);
(needs_outer_parens, needs_inner_parens)
}
}
@@ -291,7 +294,7 @@ mod tests {
};
#[test]
- fn adjustment_hints() {
+ fn adjustment_hints_prefix() {
check_with_config(
InlayHintsConfig { adjustment_hints: AdjustmentHints::Always, ..DISABLED_CONFIG },
r#"
@@ -381,6 +384,8 @@ fn main() {
&mut Struct[0];
//^^^^^^(&mut $
//^^^^^^)
+ let _: (&mut (),) = (&mut (),);
+ //^^^^^^^&mut *
}
#[derive(Copy, Clone)]
@@ -472,6 +477,9 @@ fn main() {
//^^^^^^.&
&mut Struct[0];
//^^^^^^.&mut
+ let _: (&mut (),) = (&mut (),);
+ //^^^^^^^(
+ //^^^^^^^).*.&mut
}
#[derive(Copy, Clone)]