@@ -5,7 +5,7 @@ use itertools::{Itertools, Position};
5
5
use rustc_ast:: ptr:: P ;
6
6
use rustc_ast:: util:: classify;
7
7
use rustc_ast:: util:: literal:: escape_byte_str_symbol;
8
- use rustc_ast:: util:: parser:: { self , AssocOp , Fixity } ;
8
+ use rustc_ast:: util:: parser:: { self , AssocOp , ExprPrecedence , Fixity } ;
9
9
use rustc_ast:: {
10
10
self as ast, BlockCheckMode , FormatAlignment , FormatArgPosition , FormatArgsPiece , FormatCount ,
11
11
FormatDebugHex , FormatSign , FormatTrait , token,
@@ -214,7 +214,7 @@ impl<'a> State<'a> {
214
214
fn print_expr_call ( & mut self , func : & ast:: Expr , args : & [ P < ast:: Expr > ] , fixup : FixupContext ) {
215
215
let needs_paren = match func. kind {
216
216
ast:: ExprKind :: Field ( ..) => true ,
217
- _ => func. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
217
+ _ => func. precedence ( ) < ExprPrecedence :: Unambiguous ,
218
218
} ;
219
219
220
220
// Independent of parenthesization related to precedence, we must
@@ -256,7 +256,7 @@ impl<'a> State<'a> {
256
256
// a statement containing an expression.
257
257
self . print_expr_cond_paren (
258
258
receiver,
259
- receiver. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
259
+ receiver. precedence ( ) < ExprPrecedence :: Unambiguous ,
260
260
fixup,
261
261
) ;
262
262
@@ -276,7 +276,7 @@ impl<'a> State<'a> {
276
276
fixup : FixupContext ,
277
277
) {
278
278
let assoc_op = AssocOp :: from_ast_binop ( op. node ) ;
279
- let binop_prec = assoc_op. precedence ( ) as i8 ;
279
+ let binop_prec = assoc_op. precedence ( ) ;
280
280
let left_prec = lhs. precedence ( ) ;
281
281
let right_prec = rhs. precedence ( ) ;
282
282
@@ -317,7 +317,7 @@ impl<'a> State<'a> {
317
317
self . word ( op. as_str ( ) ) ;
318
318
self . print_expr_cond_paren (
319
319
expr,
320
- expr. precedence ( ) < parser :: PREC_PREFIX ,
320
+ expr. precedence ( ) < ExprPrecedence :: Prefix ,
321
321
fixup. subsequent_subexpression ( ) ,
322
322
) ;
323
323
}
@@ -339,7 +339,7 @@ impl<'a> State<'a> {
339
339
}
340
340
self . print_expr_cond_paren (
341
341
expr,
342
- expr. precedence ( ) < parser :: PREC_PREFIX ,
342
+ expr. precedence ( ) < ExprPrecedence :: Prefix ,
343
343
fixup. subsequent_subexpression ( ) ,
344
344
) ;
345
345
}
@@ -423,10 +423,9 @@ impl<'a> State<'a> {
423
423
self . print_token_literal ( lit, expr. span )
424
424
}
425
425
ast:: ExprKind :: Cast ( expr, ty) => {
426
- let prec = AssocOp :: As . precedence ( ) as i8 ;
427
426
self . print_expr_cond_paren (
428
427
expr,
429
- expr. precedence ( ) < prec ,
428
+ expr. precedence ( ) < ExprPrecedence :: Cast ,
430
429
fixup. leftmost_subexpression ( ) ,
431
430
) ;
432
431
self . space ( ) ;
@@ -503,7 +502,7 @@ impl<'a> State<'a> {
503
502
MatchKind :: Postfix => {
504
503
self . print_expr_cond_paren (
505
504
expr,
506
- expr. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
505
+ expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
507
506
fixup,
508
507
) ;
509
508
self . word_nbsp ( ".match" ) ;
@@ -567,46 +566,46 @@ impl<'a> State<'a> {
567
566
ast:: ExprKind :: Await ( expr, _) => {
568
567
self . print_expr_cond_paren (
569
568
expr,
570
- expr. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
569
+ expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
571
570
fixup,
572
571
) ;
573
572
self . word ( ".await" ) ;
574
573
}
575
574
ast:: ExprKind :: Assign ( lhs, rhs, _) => {
576
- let prec = AssocOp :: Assign . precedence ( ) as i8 ;
577
575
self . print_expr_cond_paren (
578
576
lhs,
579
- lhs. precedence ( ) <= prec,
577
+ // Ranges are allowed on the right-hand side of assignment,
578
+ // but not the left. `(a..b) = c` needs parentheses.
579
+ lhs. precedence ( ) <= ExprPrecedence :: Range ,
580
580
fixup. leftmost_subexpression ( ) ,
581
581
) ;
582
582
self . space ( ) ;
583
583
self . word_space ( "=" ) ;
584
584
self . print_expr_cond_paren (
585
585
rhs,
586
- rhs. precedence ( ) < prec ,
586
+ rhs. precedence ( ) < ExprPrecedence :: Assign ,
587
587
fixup. subsequent_subexpression ( ) ,
588
588
) ;
589
589
}
590
590
ast:: ExprKind :: AssignOp ( op, lhs, rhs) => {
591
- let prec = AssocOp :: Assign . precedence ( ) as i8 ;
592
591
self . print_expr_cond_paren (
593
592
lhs,
594
- lhs. precedence ( ) <= prec ,
593
+ lhs. precedence ( ) <= ExprPrecedence :: Range ,
595
594
fixup. leftmost_subexpression ( ) ,
596
595
) ;
597
596
self . space ( ) ;
598
597
self . word ( op. node . as_str ( ) ) ;
599
598
self . word_space ( "=" ) ;
600
599
self . print_expr_cond_paren (
601
600
rhs,
602
- rhs. precedence ( ) < prec ,
601
+ rhs. precedence ( ) < ExprPrecedence :: Assign ,
603
602
fixup. subsequent_subexpression ( ) ,
604
603
) ;
605
604
}
606
605
ast:: ExprKind :: Field ( expr, ident) => {
607
606
self . print_expr_cond_paren (
608
607
expr,
609
- expr. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
608
+ expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
610
609
fixup,
611
610
) ;
612
611
self . word ( "." ) ;
@@ -615,7 +614,7 @@ impl<'a> State<'a> {
615
614
ast:: ExprKind :: Index ( expr, index, _) => {
616
615
self . print_expr_cond_paren (
617
616
expr,
618
- expr. precedence ( ) < parser :: PREC_UNAMBIGUOUS ,
617
+ expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
619
618
fixup. leftmost_subexpression ( ) ,
620
619
) ;
621
620
self . word ( "[" ) ;
@@ -627,7 +626,7 @@ impl<'a> State<'a> {
627
626
// than `Assign`, but `x .. x = x` gives a parse error instead of `x .. (x = x)`.
628
627
// Here we use a fake precedence value so that any child with lower precedence than
629
628
// a "normal" binop gets parenthesized. (`LOr` is the lowest-precedence binop.)
630
- let fake_prec = AssocOp :: LOr . precedence ( ) as i8 ;
629
+ let fake_prec = ExprPrecedence :: LOr ;
631
630
if let Some ( e) = start {
632
631
self . print_expr_cond_paren (
633
632
e,
@@ -662,7 +661,7 @@ impl<'a> State<'a> {
662
661
expr,
663
662
// Parenthesize if required by precedence, or in the
664
663
// case of `break 'inner: loop { break 'inner 1 } + 1`
665
- expr. precedence ( ) < parser :: PREC_JUMP
664
+ expr. precedence ( ) < ExprPrecedence :: Jump
666
665
|| ( opt_label. is_none ( ) && classify:: leading_labeled_expr ( expr) ) ,
667
666
fixup. subsequent_subexpression ( ) ,
668
667
) ;
@@ -681,7 +680,7 @@ impl<'a> State<'a> {
681
680
self . word ( " " ) ;
682
681
self . print_expr_cond_paren (
683
682
expr,
684
- expr. precedence ( ) < parser :: PREC_JUMP ,
683
+ expr. precedence ( ) < ExprPrecedence :: Jump ,
685
684
fixup. subsequent_subexpression ( ) ,
686
685
) ;
687
686
}
@@ -694,7 +693,7 @@ impl<'a> State<'a> {
694
693
self . word ( " " ) ;
695
694
self . print_expr_cond_paren (
696
695
expr,
697
- expr. precedence ( ) < parser :: PREC_JUMP ,
696
+ expr. precedence ( ) < ExprPrecedence :: Jump ,
698
697
fixup. subsequent_subexpression ( ) ,
699
698
) ;
700
699
}
@@ -704,7 +703,7 @@ impl<'a> State<'a> {
704
703
self . word ( " " ) ;
705
704
self . print_expr_cond_paren (
706
705
result,
707
- result. precedence ( ) < parser :: PREC_JUMP ,
706
+ result. precedence ( ) < ExprPrecedence :: Jump ,
708
707
fixup. subsequent_subexpression ( ) ,
709
708
) ;
710
709
}
@@ -758,13 +757,13 @@ impl<'a> State<'a> {
758
757
self . space ( ) ;
759
758
self . print_expr_cond_paren (
760
759
expr,
761
- expr. precedence ( ) < parser :: PREC_JUMP ,
760
+ expr. precedence ( ) < ExprPrecedence :: Jump ,
762
761
fixup. subsequent_subexpression ( ) ,
763
762
) ;
764
763
}
765
764
}
766
765
ast:: ExprKind :: Try ( e) => {
767
- self . print_expr_cond_paren ( e, e. precedence ( ) < parser :: PREC_UNAMBIGUOUS , fixup) ;
766
+ self . print_expr_cond_paren ( e, e. precedence ( ) < ExprPrecedence :: Unambiguous , fixup) ;
768
767
self . word ( "?" )
769
768
}
770
769
ast:: ExprKind :: TryBlock ( blk) => {
0 commit comments