@@ -985,13 +985,13 @@ impl Builder {
985
985
}
986
986
987
987
pub fn addr_of_expr ( self , e : Box < Expr > ) -> Box < Expr > {
988
- Box :: new ( Expr :: Reference ( ExprReference {
988
+ Box :: new ( parenthesize_if_necessary ( Expr :: Reference ( ExprReference {
989
989
attrs : self . attrs ,
990
990
and_token : Token ! [ & ] ( self . span ) ,
991
991
raw : Default :: default ( ) ,
992
992
mutability : self . mutbl . to_token ( ) ,
993
993
expr : e,
994
- } ) )
994
+ } ) ) )
995
995
}
996
996
997
997
pub fn mac_expr ( self , mac : Macro ) -> Box < Expr > {
@@ -2280,7 +2280,7 @@ fn expr_precedence(e: &Expr) -> u8 {
2280
2280
Expr :: Field ( _ef) => 16 ,
2281
2281
Expr :: Call ( _) | Expr :: Index ( _) => 15 ,
2282
2282
Expr :: Try ( _et) => 14 ,
2283
- Expr :: Unary ( _eu ) => 13 ,
2283
+ Expr :: Unary ( _ ) | Expr :: Reference ( _ ) => 13 ,
2284
2284
Expr :: Cast ( _ec) => 12 ,
2285
2285
Expr :: Binary ( eb) => 2 + binop_precedence ( & eb. op ) ,
2286
2286
Expr :: Assign ( _) | Expr :: AssignOp ( _) => 1 ,
@@ -2376,6 +2376,9 @@ fn parenthesize_if_necessary(mut outer: Expr) -> Expr {
2376
2376
Expr :: Unary ( ref mut eu) => {
2377
2377
parenthesize_if_gt ( & mut eu. expr ) ;
2378
2378
}
2379
+ Expr :: Reference ( ref mut er) => {
2380
+ parenthesize_if_gt ( & mut er. expr ) ;
2381
+ }
2379
2382
Expr :: Binary ( ref mut eb) => {
2380
2383
parenthesize_if_gt ( & mut eb. left ) ;
2381
2384
// Because binops associate right, parenthesize same-precedence RHS
0 commit comments