@@ -1087,6 +1087,11 @@ impl<'a> Parser<'a> {
10871087 }
10881088 }
10891089
1090+ /// Returns whether any of the given keywords are `dist` tokens ahead of the current one.
1091+ fn is_keyword_ahead ( & self , dist : usize , kws : & [ Symbol ] ) -> bool {
1092+ self . look_ahead ( dist, |t| kws. iter ( ) . any ( |& kw| t. is_keyword ( kw) ) )
1093+ }
1094+
10901095 /// Is the current token one of the keywords that signals a bare function type?
10911096 fn token_is_bare_fn_keyword ( & mut self ) -> bool {
10921097 self . check_keyword ( kw:: Fn ) ||
@@ -4270,7 +4275,7 @@ impl<'a> Parser<'a> {
42704275 self . token . is_keyword ( kw:: Async ) &&
42714276 (
42724277 ( // `async move {`
4273- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Move ) ) &&
4278+ self . is_keyword_ahead ( 1 , & [ kw:: Move ] ) &&
42744279 self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) )
42754280 ) || ( // `async {`
42764281 self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) )
@@ -4280,12 +4285,12 @@ impl<'a> Parser<'a> {
42804285
42814286 fn is_async_fn ( & self ) -> bool {
42824287 self . token . is_keyword ( kw:: Async ) &&
4283- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Fn ) )
4288+ self . is_keyword_ahead ( 1 , & [ kw:: Fn ] )
42844289 }
42854290
42864291 fn is_do_catch_block ( & self ) -> bool {
42874292 self . token . is_keyword ( kw:: Do ) &&
4288- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Catch ) ) &&
4293+ self . is_keyword_ahead ( 1 , & [ kw:: Catch ] ) &&
42894294 self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
42904295 !self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL )
42914296 }
@@ -4309,17 +4314,17 @@ impl<'a> Parser<'a> {
43094314
43104315 fn is_existential_type_decl ( & self ) -> bool {
43114316 self . token . is_keyword ( kw:: Existential ) &&
4312- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Type ) )
4317+ self . is_keyword_ahead ( 1 , & [ kw:: Type ] )
43134318 }
43144319
43154320 fn is_auto_trait_item ( & self ) -> bool {
43164321 // auto trait
4317- ( self . token . is_keyword ( kw:: Auto )
4318- && self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Trait ) ) )
4322+ ( self . token . is_keyword ( kw:: Auto ) &&
4323+ self . is_keyword_ahead ( 1 , & [ kw:: Trait ] ) )
43194324 || // unsafe auto trait
43204325 ( self . token . is_keyword ( kw:: Unsafe ) &&
4321- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Auto ) ) &&
4322- self . look_ahead ( 2 , |t| t . is_keyword ( kw:: Trait ) ) )
4326+ self . is_keyword_ahead ( 1 , & [ kw:: Auto ] ) &&
4327+ self . is_keyword_ahead ( 2 , & [ kw:: Trait ] ) )
43234328 }
43244329
43254330 fn eat_macro_def ( & mut self , attrs : & [ Attribute ] , vis : & Visibility , lo : Span )
@@ -5486,7 +5491,7 @@ impl<'a> Parser<'a> {
54865491 ( if isolated_self ( self , 1 ) {
54875492 self . bump ( ) ;
54885493 SelfKind :: Region ( None , Mutability :: Immutable )
5489- } else if self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Mut ) ) &&
5494+ } else if self . is_keyword_ahead ( 1 , & [ kw:: Mut ] ) &&
54905495 isolated_self ( self , 2 ) {
54915496 self . bump ( ) ;
54925497 self . bump ( ) ;
@@ -5497,7 +5502,7 @@ impl<'a> Parser<'a> {
54975502 let lt = self . expect_lifetime ( ) ;
54985503 SelfKind :: Region ( Some ( lt) , Mutability :: Immutable )
54995504 } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) &&
5500- self . look_ahead ( 2 , |t| t . is_keyword ( kw:: Mut ) ) &&
5505+ self . is_keyword_ahead ( 2 , & [ kw:: Mut ] ) &&
55015506 isolated_self ( self , 3 ) {
55025507 self . bump ( ) ;
55035508 let lt = self . expect_lifetime ( ) ;
@@ -5676,8 +5681,7 @@ impl<'a> Parser<'a> {
56765681 /// (returns `false` for things like `const fn`, etc.).
56775682 fn is_const_item ( & self ) -> bool {
56785683 self . token . is_keyword ( kw:: Const ) &&
5679- !self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Fn ) ) &&
5680- !self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Unsafe ) )
5684+ !self . is_keyword_ahead ( 1 , & [ kw:: Fn , kw:: Unsafe ] )
56815685 }
56825686
56835687 /// Parses all the "front matter" for a `fn` declaration, up to
@@ -5955,7 +5959,7 @@ impl<'a> Parser<'a> {
59555959 self . look_ahead ( 1 , |t| t. is_lifetime ( ) || t. is_ident ( ) ) &&
59565960 self . look_ahead ( 2 , |t| t == & token:: Gt || t == & token:: Comma ||
59575961 t == & token:: Colon || t == & token:: Eq ) ||
5958- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Const ) ) )
5962+ self . is_keyword_ahead ( 1 , & [ kw:: Const ] ) )
59595963 }
59605964
59615965 fn parse_impl_body ( & mut self ) -> PResult < ' a , ( Vec < ImplItem > , Vec < Attribute > ) > {
@@ -6316,7 +6320,7 @@ impl<'a> Parser<'a> {
63166320 // `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
63176321 // Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
63186322 // by the following tokens.
6319- if self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Crate ) ) &&
6323+ if self . is_keyword_ahead ( 1 , & [ kw:: Crate ] ) &&
63206324 self . look_ahead ( 2 , |t| t != & token:: ModSep ) // account for `pub(crate::foo)`
63216325 {
63226326 // `pub(crate)`
@@ -6328,7 +6332,7 @@ impl<'a> Parser<'a> {
63286332 VisibilityKind :: Crate ( CrateSugar :: PubCrate ) ,
63296333 ) ;
63306334 return Ok ( vis)
6331- } else if self . look_ahead ( 1 , |t| t . is_keyword ( kw:: In ) ) {
6335+ } else if self . is_keyword_ahead ( 1 , & [ kw:: In ] ) {
63326336 // `pub(in path)`
63336337 self . bump ( ) ; // `(`
63346338 self . bump ( ) ; // `in`
@@ -6340,8 +6344,7 @@ impl<'a> Parser<'a> {
63406344 } ) ;
63416345 return Ok ( vis)
63426346 } else if self . look_ahead ( 2 , |t| t == & token:: CloseDelim ( token:: Paren ) ) &&
6343- self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Super ) ||
6344- t. is_keyword ( kw:: SelfLower ) )
6347+ self . is_keyword_ahead ( 1 , & [ kw:: Super , kw:: SelfLower ] )
63456348 {
63466349 // `pub(self)` or `pub(super)`
63476350 self . bump ( ) ; // `(`
@@ -6380,13 +6383,16 @@ impl<'a> Parser<'a> {
63806383 fn parse_defaultness ( & mut self ) -> Defaultness {
63816384 // `pub` is included for better error messages
63826385 if self . check_keyword ( kw:: Default ) &&
6383- self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Impl ) ||
6384- t. is_keyword ( kw:: Const ) ||
6385- t. is_keyword ( kw:: Fn ) ||
6386- t. is_keyword ( kw:: Unsafe ) ||
6387- t. is_keyword ( kw:: Extern ) ||
6388- t. is_keyword ( kw:: Type ) ||
6389- t. is_keyword ( kw:: Pub ) ) {
6386+ self . is_keyword_ahead ( 1 , & [
6387+ kw:: Impl ,
6388+ kw:: Const ,
6389+ kw:: Fn ,
6390+ kw:: Unsafe ,
6391+ kw:: Extern ,
6392+ kw:: Type ,
6393+ kw:: Pub ,
6394+ ] )
6395+ {
63906396 self . bump ( ) ; // `default`
63916397 Defaultness :: Default
63926398 } else {
@@ -6880,7 +6886,7 @@ impl<'a> Parser<'a> {
68806886 // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
68816887 if self . check_keyword ( kw:: Type ) ||
68826888 self . check_keyword ( kw:: Existential ) &&
6883- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Type ) ) {
6889+ self . is_keyword_ahead ( 1 , & [ kw:: Type ] ) {
68846890 let existential = self . eat_keyword ( kw:: Existential ) ;
68856891 assert ! ( self . eat_keyword( kw:: Type ) ) ;
68866892 Some ( self . parse_existential_or_alias ( existential) )
@@ -7157,7 +7163,7 @@ impl<'a> Parser<'a> {
71577163 let const_span = self . prev_span ;
71587164 if self . check_keyword ( kw:: Fn )
71597165 || ( self . check_keyword ( kw:: Unsafe )
7160- && self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Fn ) ) ) {
7166+ && self . is_keyword_ahead ( 1 , & [ kw:: Fn ] ) ) {
71617167 // CONST FUNCTION ITEM
71627168 let unsafety = self . parse_unsafety ( ) ;
71637169 self . bump ( ) ;
@@ -7202,10 +7208,10 @@ impl<'a> Parser<'a> {
72027208 // `unsafe async fn` or `async fn`
72037209 if (
72047210 self . check_keyword ( kw:: Unsafe ) &&
7205- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Async ) )
7211+ self . is_keyword_ahead ( 1 , & [ kw:: Async ] )
72067212 ) || (
72077213 self . check_keyword ( kw:: Async ) &&
7208- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Fn ) )
7214+ self . is_keyword_ahead ( 1 , & [ kw:: Fn ] )
72097215 )
72107216 {
72117217 // ASYNC FUNCTION ITEM
@@ -7239,8 +7245,7 @@ impl<'a> Parser<'a> {
72397245 return Ok ( Some ( item) ) ;
72407246 }
72417247 if self . check_keyword ( kw:: Unsafe ) &&
7242- ( self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Trait ) ) ||
7243- self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Auto ) ) )
7248+ self . is_keyword_ahead ( 1 , & [ kw:: Trait , kw:: Auto ] )
72447249 {
72457250 // UNSAFE TRAIT ITEM
72467251 self . bump ( ) ; // `unsafe`
@@ -7263,11 +7268,9 @@ impl<'a> Parser<'a> {
72637268 }
72647269 if self . check_keyword ( kw:: Impl ) ||
72657270 self . check_keyword ( kw:: Unsafe ) &&
7266- self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Impl ) ) ||
7267- self . check_keyword ( kw:: Default ) &&
7268- self . look_ahead ( 1 , |t| t. is_keyword ( kw:: Impl ) ) ||
7271+ self . is_keyword_ahead ( 1 , & [ kw:: Impl ] ) ||
72697272 self . check_keyword ( kw:: Default ) &&
7270- self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Unsafe ) ) {
7273+ self . is_keyword_ahead ( 1 , & [ kw :: Impl , kw:: Unsafe ] ) {
72717274 // IMPL ITEM
72727275 let defaultness = self . parse_defaultness ( ) ;
72737276 let unsafety = self . parse_unsafety ( ) ;
@@ -7360,7 +7363,7 @@ impl<'a> Parser<'a> {
73607363 }
73617364 if self . check_keyword ( kw:: Trait )
73627365 || ( self . check_keyword ( kw:: Auto )
7363- && self . look_ahead ( 1 , |t| t . is_keyword ( kw:: Trait ) ) )
7366+ && self . is_keyword_ahead ( 1 , & [ kw:: Trait ] ) )
73647367 {
73657368 let is_auto = if self . eat_keyword ( kw:: Trait ) {
73667369 IsAuto :: No
0 commit comments