@@ -260,7 +260,7 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool,
260260 if postfix {
261261 // postfix ops have higher precedence than any other operator, so we need to wrap
262262 // any inner expression that is below (except for jumps if they don't have a value)
263- let needs_inner_parens = prec < ExprPrecedence :: Unambiguous && {
263+ let needs_inner_parens = prec < ExprPrecedence :: Postfix && {
264264 prec != ExprPrecedence :: Jump || !expr. is_ret_like_with_no_value ( )
265265 } ;
266266 // 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,
276276 // if we are already wrapped, great, no need to wrap again
277277 . filter ( |it| !matches ! ( it, ast:: Expr :: ParenExpr ( _) ) )
278278 . map ( |it| it. precedence ( ) ) ;
279+
279280 // if we have no parent, we don't need outer parens to disambiguate
280281 // otherwise anything with higher precedence than what we insert needs to wrap us
281- let needs_outer_parens = parent. is_some_and ( |prec| prec > ExprPrecedence :: Prefix ) ;
282+ // that means only postfix ops
283+ let needs_outer_parens =
284+ parent. is_some_and ( |parent_prec| parent_prec == ExprPrecedence :: Postfix ) ;
282285 ( needs_outer_parens, needs_inner_parens)
283286 }
284287}
@@ -291,7 +294,7 @@ mod tests {
291294 } ;
292295
293296 #[ test]
294- fn adjustment_hints ( ) {
297+ fn adjustment_hints_prefix ( ) {
295298 check_with_config (
296299 InlayHintsConfig { adjustment_hints : AdjustmentHints :: Always , ..DISABLED_CONFIG } ,
297300 r#"
@@ -381,6 +384,8 @@ fn main() {
381384 &mut Struct[0];
382385 //^^^^^^(&mut $
383386 //^^^^^^)
387+ let _: (&mut (),) = (&mut (),);
388+ //^^^^^^^&mut *
384389}
385390
386391#[derive(Copy, Clone)]
@@ -472,6 +477,9 @@ fn main() {
472477 //^^^^^^.&
473478 &mut Struct[0];
474479 //^^^^^^.&mut
480+ let _: (&mut (),) = (&mut (),);
481+ //^^^^^^^(
482+ //^^^^^^^).*.&mut
475483}
476484
477485#[derive(Copy, Clone)]
0 commit comments