@@ -2483,12 +2483,15 @@ impl<'a> Parser<'a> {
2483
2483
/// `check_pub` adds additional `pub` to the checks in case users place it
2484
2484
/// wrongly, can be used to ensure `pub` never comes after `default`.
2485
2485
pub ( super ) fn check_fn_front_matter ( & mut self , check_pub : bool , case : Case ) -> bool {
2486
+ const ALL_QUALS : & [ Symbol ] =
2487
+ & [ kw:: Pub , kw:: Gen , kw:: Const , kw:: Async , kw:: Unsafe , kw:: Safe , kw:: Extern ] ;
2488
+
2486
2489
// We use an over-approximation here.
2487
2490
// `const const`, `fn const` won't parse, but we're not stepping over other syntax either.
2488
2491
// `pub` is added in case users got confused with the ordering like `async pub fn`,
2489
2492
// only if it wasn't preceded by `default` as `default pub` is invalid.
2490
2493
let quals: & [ Symbol ] = if check_pub {
2491
- & [ kw :: Pub , kw :: Gen , kw :: Const , kw :: Async , kw :: Unsafe , kw :: Safe , kw :: Extern ]
2494
+ ALL_QUALS
2492
2495
} else {
2493
2496
& [ kw:: Gen , kw:: Const , kw:: Async , kw:: Unsafe , kw:: Safe , kw:: Extern ]
2494
2497
} ;
@@ -2518,9 +2521,9 @@ impl<'a> Parser<'a> {
2518
2521
|| self . check_keyword_case ( kw:: Extern , case)
2519
2522
&& self . look_ahead ( 1 , |t| t. can_begin_string_literal ( ) )
2520
2523
&& ( self . look_ahead ( 2 , |t| t. is_keyword_case ( kw:: Fn , case) ) ||
2521
- // this branch is only for better diagnostic in later , `pub` is not allowed here
2524
+ // this branch is only for better diagnostics; `pub` , `unsafe`, etc. are not allowed here
2522
2525
( self . may_recover ( )
2523
- && self . look_ahead ( 2 , |t| t. is_keyword ( kw:: Pub ) )
2526
+ && self . look_ahead ( 2 , |t| ALL_QUALS . iter ( ) . any ( | & kw| t. is_keyword ( kw) ) )
2524
2527
&& self . look_ahead ( 3 , |t| t. is_keyword_case ( kw:: Fn , case) ) ) )
2525
2528
}
2526
2529
0 commit comments