File tree Expand file tree Collapse file tree 3 files changed +13
-23
lines changed Expand file tree Collapse file tree 3 files changed +13
-23
lines changed Original file line number Diff line number Diff line change @@ -3253,30 +3253,12 @@ pub(crate) mod printing {
3253
3253
} ;
3254
3254
3255
3255
// These cases require parenthesization independently of precedence.
3256
- match ( & * e . left , & e. op ) {
3256
+ if let BinOp :: Lt ( _ ) | BinOp :: Shl ( _ ) = & e. op {
3257
3257
// `x as i32 < y` has the parser thinking that `i32 < y` is the
3258
3258
// beginning of a path type. It starts trying to parse `x as (i32 <
3259
3259
// y ...` instead of `(x as i32) < ...`. We need to convince it
3260
3260
// _not_ to do that.
3261
- ( _, BinOp :: Lt ( _) | BinOp :: Shl ( _) ) if classify:: confusable_with_adjacent_lt ( & e. left ) => {
3262
- left_needs_group = true ;
3263
- }
3264
-
3265
- // We are given `(let _ = a) OP b`.
3266
- //
3267
- // - When `OP <= LAnd` we should print `let _ = a OP b` to avoid
3268
- // redundant parens as the parser will interpret this as `(let _ =
3269
- // a) OP b`.
3270
- //
3271
- // - Otherwise, e.g. when we have `(let a = b) < c` in AST, parens
3272
- // are required since the parser would interpret `let a = b < c`
3273
- // as `let a = (b < c)`. To achieve this, we force parens.
3274
- #[ cfg( feature = "full" ) ]
3275
- ( Expr :: Let ( _) , _) if binop_prec > Precedence :: And => {
3276
- left_needs_group = true ;
3277
- }
3278
-
3279
- _ => { }
3261
+ left_needs_group |= classify:: confusable_with_adjacent_lt ( & e. left ) ;
3280
3262
}
3281
3263
3282
3264
print_subexpression (
Original file line number Diff line number Diff line change @@ -239,7 +239,7 @@ impl FixupContext {
239
239
/// "let chain".
240
240
pub fn needs_group_as_let_scrutinee ( self , expr : & Expr ) -> bool {
241
241
self . parenthesize_exterior_struct_lit && classify:: confusable_with_adjacent_block ( expr)
242
- || self . trailing_precedence ( expr) <= Precedence :: And
242
+ || self . trailing_precedence ( expr) < Precedence :: Let
243
243
}
244
244
245
245
/// Determines the effective precedence of a left subexpression. Some
@@ -265,7 +265,11 @@ impl FixupContext {
265
265
match expr {
266
266
// Increase precedence of expressions that extend to the end of
267
267
// current statement or group.
268
- Expr :: Break ( _) | Expr :: Closure ( _) | Expr :: Return ( _) | Expr :: Yield ( _) => {
268
+ Expr :: Break ( _)
269
+ | Expr :: Closure ( _)
270
+ | Expr :: Let ( _)
271
+ | Expr :: Return ( _)
272
+ | Expr :: Yield ( _) => {
269
273
return Precedence :: Prefix ;
270
274
}
271
275
Expr :: Range ( e) if e. start . is_none ( ) => return Precedence :: Prefix ,
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ pub(crate) enum Precedence {
19
19
Or ,
20
20
// &&
21
21
And ,
22
+ // let
23
+ #[ cfg( feature = "printing" ) ]
24
+ Let ,
22
25
// == != < > <= >=
23
26
Compare ,
24
27
// |
@@ -97,8 +100,9 @@ impl Precedence {
97
100
Expr :: Assign ( _) => Precedence :: Assign ,
98
101
Expr :: Range ( _) => Precedence :: Range ,
99
102
Expr :: Binary ( e) => Precedence :: of_binop ( & e. op ) ,
103
+ Expr :: Let ( _) => Precedence :: Let ,
100
104
Expr :: Cast ( _) => Precedence :: Cast ,
101
- Expr :: Let ( _ ) | Expr :: Reference ( _) | Expr :: Unary ( _) => Precedence :: Prefix ,
105
+ Expr :: Reference ( _) | Expr :: Unary ( _) => Precedence :: Prefix ,
102
106
103
107
Expr :: Array ( _)
104
108
| Expr :: Async ( _)
You can’t perform that action at this time.
0 commit comments