@@ -5,7 +5,7 @@ use crate::maybe_whole;
5
5
6
6
use rustc_error_codes:: * ;
7
7
use rustc_errors:: { Applicability , DiagnosticBuilder , PResult , StashKey } ;
8
- use rustc_span:: source_map:: { self , respan, Span } ;
8
+ use rustc_span:: source_map:: { self , respan, Span , Spanned } ;
9
9
use rustc_span:: symbol:: { kw, sym, Symbol } ;
10
10
use rustc_span:: BytePos ;
11
11
use syntax:: ast:: { self , AttrKind , AttrStyle , AttrVec , Attribute , Ident , DUMMY_NODE_ID } ;
@@ -561,8 +561,9 @@ impl<'a> Parser<'a> {
561
561
} ;
562
562
563
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 )
564
+ let span = self . prev_span ;
565
+ self . sess . gated_spans . gate ( sym:: const_trait_impl, span) ;
566
+ Some ( respan ( span, Constness :: Const ) )
566
567
} else {
567
568
None
568
569
} ;
@@ -627,6 +628,7 @@ impl<'a> Parser<'a> {
627
628
err_path ( ty_first. span )
628
629
}
629
630
} ;
631
+ let constness = constness. map ( |c| c. node ) ;
630
632
let trait_ref = TraitRef { path, constness, ref_id : ty_first. id } ;
631
633
632
634
ItemKind :: Impl (
@@ -640,6 +642,13 @@ impl<'a> Parser<'a> {
640
642
)
641
643
}
642
644
None => {
645
+ // Reject `impl const Type {}` here
646
+ if let Some ( Spanned { node : Constness :: Const , span } ) = constness {
647
+ self . struct_span_err ( span, "`const` cannot modify an inherent impl" )
648
+ . help ( "only a trait impl can be `const`" )
649
+ . emit ( ) ;
650
+ }
651
+
643
652
// impl Type
644
653
ItemKind :: Impl (
645
654
unsafety,
0 commit comments