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