@@ -270,31 +270,36 @@ impl<'a> Parser<'a> {
270270 let pat = self . maybe_recover_from_bad_qpath ( pat, true ) ?;
271271
272272 if !allow_range_pat {
273- match pat. node {
274- PatKind :: Range (
275- _, _, Spanned { node : RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , .. }
276- ) => { } ,
277- PatKind :: Range ( ..) => {
278- let mut err = self . struct_span_err (
279- pat. span ,
280- "the range pattern here has ambiguous interpretation" ,
281- ) ;
282- err. span_suggestion (
283- pat. span ,
284- "add parentheses to clarify the precedence" ,
285- format ! ( "({})" , pprust:: pat_to_string( & pat) ) ,
286- // "ambiguous interpretation" implies that we have to be guessing
287- Applicability :: MaybeIncorrect
288- ) ;
289- return Err ( err) ;
290- }
291- _ => { }
292- }
273+ self . ban_pat_range_if_ambiguous ( & pat) ?
293274 }
294275
295276 Ok ( pat)
296277 }
297278
279+ /// Ban a range pattern if it has an ambiguous interpretation.
280+ fn ban_pat_range_if_ambiguous ( & self , pat : & Pat ) -> PResult < ' a , ( ) > {
281+ match pat. node {
282+ PatKind :: Range (
283+ .., Spanned { node : RangeEnd :: Included ( RangeSyntax :: DotDotDot ) , .. }
284+ ) => return Ok ( ( ) ) ,
285+ PatKind :: Range ( ..) => { }
286+ _ => return Ok ( ( ) ) ,
287+ }
288+
289+ let mut err = self . struct_span_err (
290+ pat. span ,
291+ "the range pattern here has ambiguous interpretation" ,
292+ ) ;
293+ err. span_suggestion (
294+ pat. span ,
295+ "add parentheses to clarify the precedence" ,
296+ format ! ( "({})" , pprust:: pat_to_string( & pat) ) ,
297+ // "ambiguous interpretation" implies that we have to be guessing
298+ Applicability :: MaybeIncorrect
299+ ) ;
300+ Err ( err)
301+ }
302+
298303 /// Parse `&pat` / `&mut pat`.
299304 fn parse_pat_deref ( & mut self , expected : Option < & ' static str > ) -> PResult < ' a , PatKind > {
300305 self . expect_and ( ) ?;
0 commit comments