1
1
// ignore-tidy-filelength
2
2
3
3
use core:: mem;
4
- use core:: ops:: ControlFlow ;
4
+ use core:: ops:: { Bound , ControlFlow } ;
5
5
6
6
use ast:: mut_visit:: { self , MutVisitor } ;
7
7
use ast:: token:: IdentIsRaw ;
@@ -120,15 +120,15 @@ impl<'a> Parser<'a> {
120
120
r : Restrictions ,
121
121
attrs : AttrWrapper ,
122
122
) -> 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) )
124
124
}
125
125
126
126
/// Parses an associative expression with operators of at least `min_prec` precedence.
127
127
/// The `bool` in the return value indicates if it was an assoc expr, i.e. with an operator
128
128
/// followed by a subexpression (e.g. `1 + 2`).
129
129
pub ( super ) fn parse_expr_assoc_with (
130
130
& mut self ,
131
- min_prec : usize ,
131
+ min_prec : Bound < usize > ,
132
132
attrs : AttrWrapper ,
133
133
) -> PResult < ' a , ( P < Expr > , bool ) > {
134
134
let lhs = if self . token . is_range_separator ( ) {
@@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
144
144
/// was actually parsed.
145
145
pub ( super ) fn parse_expr_assoc_rest_with (
146
146
& mut self ,
147
- min_prec : usize ,
147
+ min_prec : Bound < usize > ,
148
148
starts_stmt : bool ,
149
149
mut lhs : P < Expr > ,
150
150
) -> PResult < ' a , ( P < Expr > , bool ) > {
@@ -163,7 +163,11 @@ impl<'a> Parser<'a> {
163
163
self . restrictions
164
164
} ;
165
165
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
+ } {
167
171
break ;
168
172
}
169
173
// Check for deprecated `...` syntax
@@ -276,16 +280,16 @@ impl<'a> Parser<'a> {
276
280
}
277
281
278
282
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 ) ,
282
286
// We currently have no non-associative operators that are not handled above by
283
287
// the special cases. The code is here only for future convenience.
284
- Fixity :: None => 1 ,
288
+ Fixity :: None => Bound :: Excluded ( prec ) ,
285
289
} ;
286
290
let ( rhs, _) = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
287
291
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)
289
293
} ) ?;
290
294
291
295
let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -460,7 +464,7 @@ impl<'a> Parser<'a> {
460
464
let maybe_lt = self . token . clone ( ) ;
461
465
let attrs = self . parse_outer_attributes ( ) ?;
462
466
Some (
463
- self . parse_expr_assoc_with ( prec + 1 , attrs)
467
+ self . parse_expr_assoc_with ( Bound :: Excluded ( prec) , attrs)
464
468
. map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
465
469
. 0 ,
466
470
)
@@ -518,7 +522,7 @@ impl<'a> Parser<'a> {
518
522
let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
519
523
// RHS must be parsed with more associativity than the dots.
520
524
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)
522
526
. map ( |( x, _) | ( lo. to ( x. span ) , Some ( x) ) )
523
527
. map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
524
528
} else {
@@ -2643,7 +2647,8 @@ impl<'a> Parser<'a> {
2643
2647
self . expect ( & token:: Eq ) ?;
2644
2648
}
2645
2649
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) ?;
2647
2652
let span = lo. to ( expr. span ) ;
2648
2653
Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
2649
2654
}
0 commit comments