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