@@ -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:: {
@@ -247,6 +248,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
247248 [ sym:: coroutine, ..] => {
248249 self . check_coroutine ( attr, target) ;
249250 }
251+ [ sym:: type_const, ..] => {
252+ self . check_type_const ( hir_id, attr, target) ;
253+ }
250254 [ sym:: linkage, ..] => self . check_linkage ( attr, span, target) ,
251255 [ sym:: rustc_pub_transparent, ..] => self . check_rustc_pub_transparent ( attr. span , span, attrs) ,
252256 [
@@ -2493,6 +2497,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24932497 }
24942498 }
24952499
2500+ fn check_type_const ( & self , hir_id : HirId , attr : & Attribute , target : Target ) {
2501+ let tcx = self . tcx ;
2502+ if target == Target :: AssocConst
2503+ && let parent = tcx. parent ( hir_id. expect_owner ( ) . to_def_id ( ) )
2504+ && self . tcx . def_kind ( parent) == DefKind :: Trait
2505+ {
2506+ return ;
2507+ } else {
2508+ self . dcx ( )
2509+ . struct_span_err (
2510+ attr. span ,
2511+ "`#[type_const]` must only be applied to trait associated constants" ,
2512+ )
2513+ . emit ( ) ;
2514+ }
2515+ }
2516+
24962517 fn check_linkage ( & self , attr : & Attribute , span : Span , target : Target ) {
24972518 match target {
24982519 Target :: Fn
0 commit comments