11// ignore-tidy-filelength
22
33use core:: mem;
4- use core:: ops:: ControlFlow ;
4+ use core:: ops:: { Bound , ControlFlow } ;
55
66use ast:: mut_visit:: { self , MutVisitor } ;
77use ast:: token:: IdentIsRaw ;
@@ -120,15 +120,15 @@ impl<'a> Parser<'a> {
120120 r : Restrictions ,
121121 attrs : AttrWrapper ,
122122 ) -> PResult < ' a , ( P < Expr > , bool ) > {
123- self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , attrs) )
123+ self . with_res ( r, |this| this. parse_expr_assoc_with ( Bound :: Unbounded , attrs) )
124124 }
125125
126126 /// Parses an associative expression with operators of at least `min_prec` precedence.
127127 /// The `bool` in the return value indicates if it was an assoc expr, i.e. with an operator
128128 /// followed by a subexpression (e.g. `1 + 2`).
129129 pub ( super ) fn parse_expr_assoc_with (
130130 & mut self ,
131- min_prec : usize ,
131+ min_prec : Bound < usize > ,
132132 attrs : AttrWrapper ,
133133 ) -> PResult < ' a , ( P < Expr > , bool ) > {
134134 let lhs = if self . token . is_range_separator ( ) {
@@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
144144 /// was actually parsed.
145145 pub ( super ) fn parse_expr_assoc_rest_with (
146146 & mut self ,
147- min_prec : usize ,
147+ min_prec : Bound < usize > ,
148148 starts_stmt : bool ,
149149 mut lhs : P < Expr > ,
150150 ) -> PResult < ' a , ( P < Expr > , bool ) > {
@@ -163,7 +163,11 @@ impl<'a> Parser<'a> {
163163 self . restrictions
164164 } ;
165165 let prec = op. node . precedence ( ) ;
166- if prec < min_prec {
166+ if match min_prec {
167+ Bound :: Included ( min_prec) => prec < min_prec,
168+ Bound :: Excluded ( min_prec) => prec <= min_prec,
169+ Bound :: Unbounded => false ,
170+ } {
167171 break ;
168172 }
169173 // Check for deprecated `...` syntax
@@ -276,16 +280,16 @@ impl<'a> Parser<'a> {
276280 }
277281
278282 let fixity = op. fixity ( ) ;
279- let prec_adjustment = match fixity {
280- Fixity :: Right => 0 ,
281- Fixity :: Left => 1 ,
283+ let min_prec = match fixity {
284+ Fixity :: Right => Bound :: Included ( prec ) ,
285+ Fixity :: Left => Bound :: Excluded ( prec ) ,
282286 // We currently have no non-associative operators that are not handled above by
283287 // the special cases. The code is here only for future convenience.
284- Fixity :: None => 1 ,
288+ Fixity :: None => Bound :: Excluded ( prec ) ,
285289 } ;
286290 let ( rhs, _) = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
287291 let attrs = this. parse_outer_attributes ( ) ?;
288- this. parse_expr_assoc_with ( prec + prec_adjustment , attrs)
292+ this. parse_expr_assoc_with ( min_prec , attrs)
289293 } ) ?;
290294
291295 let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -460,7 +464,7 @@ impl<'a> Parser<'a> {
460464 let maybe_lt = self . token . clone ( ) ;
461465 let attrs = self . parse_outer_attributes ( ) ?;
462466 Some (
463- self . parse_expr_assoc_with ( prec + 1 , attrs)
467+ self . parse_expr_assoc_with ( Bound :: Excluded ( prec) , attrs)
464468 . map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
465469 . 0 ,
466470 )
@@ -518,7 +522,7 @@ impl<'a> Parser<'a> {
518522 let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
519523 // RHS must be parsed with more associativity than the dots.
520524 let attrs = this. parse_outer_attributes ( ) ?;
521- this. parse_expr_assoc_with ( op. unwrap ( ) . precedence ( ) + 1 , attrs)
525+ this. parse_expr_assoc_with ( Bound :: Excluded ( op. unwrap ( ) . precedence ( ) ) , attrs)
522526 . map ( |( x, _) | ( lo. to ( x. span ) , Some ( x) ) )
523527 . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
524528 } else {
@@ -2643,7 +2647,8 @@ impl<'a> Parser<'a> {
26432647 self . expect ( & token:: Eq ) ?;
26442648 }
26452649 let attrs = self . parse_outer_attributes ( ) ?;
2646- let ( expr, _) = self . parse_expr_assoc_with ( 1 + prec_let_scrutinee_needs_par ( ) , attrs) ?;
2650+ let ( expr, _) =
2651+ self . parse_expr_assoc_with ( Bound :: Excluded ( prec_let_scrutinee_needs_par ( ) ) , attrs) ?;
26472652 let span = lo. to ( expr. span ) ;
26482653 Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
26492654 }
0 commit comments