@@ -260,7 +260,7 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool,
260
260
if postfix {
261
261
// postfix ops have higher precedence than any other operator, so we need to wrap
262
262
// 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 && {
264
264
prec != ExprPrecedence :: Jump || !expr. is_ret_like_with_no_value ( )
265
265
} ;
266
266
// 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,
276
276
// if we are already wrapped, great, no need to wrap again
277
277
. filter ( |it| !matches ! ( it, ast:: Expr :: ParenExpr ( _) ) )
278
278
. map ( |it| it. precedence ( ) ) ;
279
+
279
280
// if we have no parent, we don't need outer parens to disambiguate
280
281
// 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 ) ;
282
285
( needs_outer_parens, needs_inner_parens)
283
286
}
284
287
}
@@ -291,7 +294,7 @@ mod tests {
291
294
} ;
292
295
293
296
#[ test]
294
- fn adjustment_hints ( ) {
297
+ fn adjustment_hints_prefix ( ) {
295
298
check_with_config (
296
299
InlayHintsConfig { adjustment_hints : AdjustmentHints :: Always , ..DISABLED_CONFIG } ,
297
300
r#"
@@ -381,6 +384,8 @@ fn main() {
381
384
&mut Struct[0];
382
385
//^^^^^^(&mut $
383
386
//^^^^^^)
387
+ let _: (&mut (),) = (&mut (),);
388
+ //^^^^^^^&mut *
384
389
}
385
390
386
391
#[derive(Copy, Clone)]
@@ -472,6 +477,9 @@ fn main() {
472
477
//^^^^^^.&
473
478
&mut Struct[0];
474
479
//^^^^^^.&mut
480
+ let _: (&mut (),) = (&mut (),);
481
+ //^^^^^^^(
482
+ //^^^^^^^).*.&mut
475
483
}
476
484
477
485
#[derive(Copy, Clone)]
0 commit comments