@@ -147,10 +147,7 @@ impl<'a> Parser<'a> {
147
147
|| self . check_keyword ( kw:: Default ) && self . is_keyword_ahead ( 1 , & [ kw:: Impl , kw:: Unsafe ] )
148
148
{
149
149
// IMPL ITEM
150
- let defaultness = self . parse_defaultness ( ) ;
151
- let unsafety = self . parse_unsafety ( ) ;
152
- self . expect_keyword ( kw:: Impl ) ?;
153
- self . parse_item_impl ( attrs, unsafety, defaultness) ?
150
+ self . parse_item_impl ( attrs) ?
154
151
} else if self . eat_keyword ( kw:: Mod ) {
155
152
// MODULE ITEM
156
153
self . parse_item_mod ( attrs) ?
@@ -349,7 +346,7 @@ impl<'a> Parser<'a> {
349
346
err
350
347
}
351
348
352
- /// Parses an implementation item, `impl` keyword is already parsed .
349
+ /// Parses an implementation item.
353
350
///
354
351
/// ```
355
352
/// impl<'a, T> TYPE { /* impl items */ }
@@ -363,12 +360,11 @@ impl<'a> Parser<'a> {
363
360
/// "impl" GENERICS "const"? "!"? TYPE "for"? (TYPE | "..") ("where" PREDICATES)? "{" BODY "}"
364
361
/// "impl" GENERICS "const"? "!"? TYPE ("where" PREDICATES)? "{" BODY "}"
365
362
/// ```
366
- fn parse_item_impl (
367
- & mut self ,
368
- attrs : & mut Vec < Attribute > ,
369
- unsafety : Unsafe ,
370
- defaultness : Defaultness ,
371
- ) -> PResult < ' a , ItemInfo > {
363
+ fn parse_item_impl ( & mut self , attrs : & mut Vec < Attribute > ) -> PResult < ' a , ItemInfo > {
364
+ let defaultness = self . parse_defaultness ( ) ;
365
+ let unsafety = self . parse_unsafety ( ) ;
366
+ self . expect_keyword ( kw:: Impl ) ?;
367
+
372
368
// First, parse generic parameters if necessary.
373
369
let mut generics = if self . choose_generics_over_qpath ( ) {
374
370
self . parse_generics ( ) ?
@@ -529,22 +525,13 @@ impl<'a> Parser<'a> {
529
525
530
526
/// Parses defaultness (i.e., `default` or nothing).
531
527
fn parse_defaultness ( & mut self ) -> Defaultness {
532
- // `pub` is included for better error messages
528
+ // We are interested in `default` followed by another keyword.
529
+ // However, we must avoid keywords that occur as binary operators.
530
+ // Currently, the only applicable keyword is `as` (`default as Ty`).
533
531
if self . check_keyword ( kw:: Default )
534
- && self . is_keyword_ahead (
535
- 1 ,
536
- & [
537
- kw:: Impl ,
538
- kw:: Static ,
539
- kw:: Const ,
540
- kw:: Async ,
541
- kw:: Fn ,
542
- kw:: Unsafe ,
543
- kw:: Extern ,
544
- kw:: Type ,
545
- kw:: Pub ,
546
- ] ,
547
- )
532
+ && self . look_ahead ( 1 , |t| {
533
+ t. is_non_raw_ident_where ( |i| i. is_reserved ( ) && i. name != kw:: As )
534
+ } )
548
535
{
549
536
self . bump ( ) ; // `default`
550
537
Defaultness :: Default ( self . prev_span )
0 commit comments