@@ -11,6 +11,7 @@ use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, as
1111use rustc_data_structures:: fx:: FxHashMap ;
1212use rustc_errors:: { Applicability , DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
1313use rustc_feature:: { AttributeDuplicates , AttributeType , BUILTIN_ATTRIBUTE_MAP , BuiltinAttribute } ;
14+ use rustc_hir:: def:: DefKind ;
1415use rustc_hir:: def_id:: LocalModDefId ;
1516use rustc_hir:: intravisit:: { self , Visitor } ;
1617use rustc_hir:: {
@@ -246,6 +247,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
246247 [ sym:: coroutine, ..] => {
247248 self . check_coroutine ( attr, target) ;
248249 }
250+ [ sym:: type_const, ..] => {
251+ self . check_type_const ( hir_id, attr, target) ;
252+ }
249253 [ sym:: linkage, ..] => self . check_linkage ( attr, span, target) ,
250254 [ sym:: rustc_pub_transparent, ..] => self . check_rustc_pub_transparent ( attr. span , span, attrs) ,
251255 [
@@ -2455,6 +2459,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24552459 }
24562460 }
24572461
2462+ fn check_type_const ( & self , hir_id : HirId , attr : & Attribute , target : Target ) {
2463+ let tcx = self . tcx ;
2464+ if target == Target :: AssocConst
2465+ && let parent = tcx. parent ( hir_id. expect_owner ( ) . to_def_id ( ) )
2466+ && self . tcx . def_kind ( parent) == DefKind :: Trait
2467+ {
2468+ return ;
2469+ } else {
2470+ self . dcx ( )
2471+ . struct_span_err (
2472+ attr. span ,
2473+ "`#[type_const]` must only be applied to trait associated constants" ,
2474+ )
2475+ . emit ( ) ;
2476+ }
2477+ }
2478+
24582479 fn check_linkage ( & self , attr : & Attribute , span : Span , target : Target ) {
24592480 match target {
24602481 Target :: Fn
0 commit comments