@@ -542,10 +542,11 @@ impl<'a> Parser<'a> {
542
542
/// impl<'a, T> TYPE { /* impl items */ }
543
543
/// impl<'a, T> TRAIT for TYPE { /* impl items */ }
544
544
/// impl<'a, T> !TRAIT for TYPE { /* impl items */ }
545
+ /// impl<'a, T> const TRAIT for TYPE { /* impl items */ }
545
546
///
546
547
/// We actually parse slightly more relaxed grammar for better error reporting and recovery.
547
- /// `impl` GENERICS `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
548
- /// `impl` GENERICS `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
548
+ /// `impl` GENERICS `const`? `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
549
+ /// `impl` GENERICS `const`? `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
549
550
fn parse_item_impl (
550
551
& mut self ,
551
552
unsafety : Unsafety ,
@@ -558,6 +559,13 @@ impl<'a> Parser<'a> {
558
559
Generics :: default ( )
559
560
} ;
560
561
562
+ let constness = if self . eat_keyword ( kw:: Const ) {
563
+ self . sess . gated_spans . gate ( sym:: const_trait_impl, self . prev_span ) ;
564
+ Some ( Constness :: Const )
565
+ } else {
566
+ None
567
+ } ;
568
+
561
569
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
562
570
let polarity = if self . check ( & token:: Not ) && self . look_ahead ( 1 , |t| t. can_begin_type ( ) ) {
563
571
self . bump ( ) ; // `!`
@@ -618,7 +626,7 @@ impl<'a> Parser<'a> {
618
626
err_path ( ty_first. span )
619
627
}
620
628
} ;
621
- let trait_ref = TraitRef { path, ref_id : ty_first. id } ;
629
+ let trait_ref = TraitRef { path, constness , ref_id : ty_first. id } ;
622
630
623
631
ItemKind :: Impl (
624
632
unsafety,
0 commit comments