@@ -202,26 +202,10 @@ impl<'a> Parser<'a> {
202
202
} else {
203
203
// Try to parse everything else as literal with optional minus
204
204
match self . parse_literal_maybe_minus ( ) {
205
- Ok ( begin) => {
206
- let op_span = self . token . span ;
207
- if self . check ( & token:: DotDot ) || self . check ( & token:: DotDotEq ) ||
208
- self . check ( & token:: DotDotDot ) {
209
- let ( end_kind, form) = if self . eat ( & token:: DotDotDot ) {
210
- ( RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , "..." )
211
- } else if self . eat ( & token:: DotDotEq ) {
212
- ( RangeEnd :: Included ( RangeSyntax :: DotDotEq ) , "..=" )
213
- } else if self . eat ( & token:: DotDot ) {
214
- ( RangeEnd :: Excluded , ".." )
215
- } else {
216
- panic ! ( "impossible case: we already matched \
217
- on a range-operator token")
218
- } ;
219
- let end = self . parse_pat_range_end_opt ( & begin, form) ?;
220
- PatKind :: Range ( begin, end, respan ( op_span, end_kind) )
221
- } else {
222
- PatKind :: Lit ( begin)
223
- }
224
- }
205
+ Ok ( begin) if self . check ( & token:: DotDot ) || self . check ( & token:: DotDotEq )
206
+ || self . check ( & token:: DotDotDot )
207
+ => self . parse_pat_range_starting_with_lit ( begin) ?,
208
+ Ok ( begin) => PatKind :: Lit ( begin) ,
225
209
Err ( mut err) => {
226
210
self . cancel ( & mut err) ;
227
211
let expected = expected. unwrap_or ( "pattern" ) ;
@@ -360,6 +344,23 @@ impl<'a> Parser<'a> {
360
344
Ok ( PatKind :: Range ( begin, end, respan ( op_span, end_kind) ) )
361
345
}
362
346
347
+ /// Parse a range pattern `$literal $form $end?` where `$form = ".." | "..." | "..=" ;`.
348
+ /// The `$path` has already been parsed and the next token is the `$form`.
349
+ fn parse_pat_range_starting_with_lit ( & mut self , begin : P < Expr > ) -> PResult < ' a , PatKind > {
350
+ let op_span = self . token . span ;
351
+ let ( end_kind, form) = if self . eat ( & token:: DotDotDot ) {
352
+ ( RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , "..." )
353
+ } else if self . eat ( & token:: DotDotEq ) {
354
+ ( RangeEnd :: Included ( RangeSyntax :: DotDotEq ) , "..=" )
355
+ } else if self . eat ( & token:: DotDot ) {
356
+ ( RangeEnd :: Excluded , ".." )
357
+ } else {
358
+ panic ! ( "impossible case: we already matched on a range-operator token" )
359
+ } ;
360
+ let end = self . parse_pat_range_end_opt ( & begin, form) ?;
361
+ Ok ( PatKind :: Range ( begin, end, respan ( op_span, end_kind) ) )
362
+ }
363
+
363
364
// Helper function to decide whether to parse as ident binding
364
365
// or to try to do something more complex like range patterns.
365
366
fn parse_as_ident ( & mut self ) -> bool {
0 commit comments