@@ -3,7 +3,7 @@ use super::{Parser, PResult, PathStyle};
3
3
use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole} ;
4
4
use crate :: ptr:: P ;
5
5
use crate :: ast:: { self , Attribute , Pat , PatKind , FieldPat , RangeEnd , RangeSyntax , Mac_ } ;
6
- use crate :: ast:: { BindingMode , Ident , Mutability , Path , Expr , ExprKind } ;
6
+ use crate :: ast:: { BindingMode , Ident , Mutability , Path , QSelf , Expr , ExprKind } ;
7
7
use crate :: parse:: token:: { self } ;
8
8
use crate :: print:: pprust;
9
9
use crate :: source_map:: { respan, Span , Spanned } ;
@@ -167,20 +167,7 @@ impl<'a> Parser<'a> {
167
167
match self . token . kind {
168
168
token:: Not if qself. is_none ( ) => self . parse_pat_mac_invoc ( lo, path) ?,
169
169
token:: DotDotDot | token:: DotDotEq | token:: DotDot => {
170
- let ( end_kind, form) = match self . token . kind {
171
- token:: DotDot => ( RangeEnd :: Excluded , ".." ) ,
172
- token:: DotDotDot => ( RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , "..." ) ,
173
- token:: DotDotEq => ( RangeEnd :: Included ( RangeSyntax :: DotDotEq ) , "..=" ) ,
174
- _ => panic ! ( "can only parse `..`/`...`/`..=` for ranges \
175
- (checked above)") ,
176
- } ;
177
- let op_span = self . token . span ;
178
- // Parse range
179
- let span = lo. to ( self . prev_span ) ;
180
- let begin = self . mk_expr ( span, ExprKind :: Path ( qself, path) , ThinVec :: new ( ) ) ;
181
- self . bump ( ) ;
182
- let end = self . parse_pat_range_end_opt ( & begin, form) ?;
183
- PatKind :: Range ( begin, end, respan ( op_span, end_kind) )
170
+ self . parse_pat_range_starting_with_path ( lo, qself, path) ?
184
171
}
185
172
token:: OpenDelim ( token:: Brace ) => {
186
173
if qself. is_some ( ) {
@@ -350,6 +337,29 @@ impl<'a> Parser<'a> {
350
337
Ok ( PatKind :: Mac ( mac) )
351
338
}
352
339
340
+ /// Parse a range pattern `$path $form $end?` where `$form = ".." | "..." | "..=" ;`.
341
+ /// The `$path` has already been parsed and the next token is the `$form`.
342
+ fn parse_pat_range_starting_with_path (
343
+ & mut self ,
344
+ lo : Span ,
345
+ qself : Option < QSelf > ,
346
+ path : Path
347
+ ) -> PResult < ' a , PatKind > {
348
+ let ( end_kind, form) = match self . token . kind {
349
+ token:: DotDot => ( RangeEnd :: Excluded , ".." ) ,
350
+ token:: DotDotDot => ( RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , "..." ) ,
351
+ token:: DotDotEq => ( RangeEnd :: Included ( RangeSyntax :: DotDotEq ) , "..=" ) ,
352
+ _ => panic ! ( "can only parse `..`/`...`/`..=` for ranges (checked above)" ) ,
353
+ } ;
354
+ let op_span = self . token . span ;
355
+ // Parse range
356
+ let span = lo. to ( self . prev_span ) ;
357
+ let begin = self . mk_expr ( span, ExprKind :: Path ( qself, path) , ThinVec :: new ( ) ) ;
358
+ self . bump ( ) ;
359
+ let end = self . parse_pat_range_end_opt ( & begin, form) ?;
360
+ Ok ( PatKind :: Range ( begin, end, respan ( op_span, end_kind) ) )
361
+ }
362
+
353
363
// Helper function to decide whether to parse as ident binding
354
364
// or to try to do something more complex like range patterns.
355
365
fn parse_as_ident ( & mut self ) -> bool {
0 commit comments