@@ -14,6 +14,7 @@ use rustc_attr_parsing::{AttributeKind, ReprAttr, find_attr};
1414use rustc_data_structures:: fx:: FxHashMap ;
1515use rustc_errors:: { Applicability , DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
1616use rustc_feature:: { AttributeDuplicates , AttributeType , BUILTIN_ATTRIBUTE_MAP , BuiltinAttribute } ;
17+ use rustc_hir:: def:: DefKind ;
1718use rustc_hir:: def_id:: LocalModDefId ;
1819use rustc_hir:: intravisit:: { self , Visitor } ;
1920use rustc_hir:: {
@@ -257,6 +258,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
257258 [ sym:: coroutine, ..] => {
258259 self . check_coroutine ( attr, target) ;
259260 }
261+ [ sym:: type_const, ..] => {
262+ self . check_type_const ( hir_id, attr, target) ;
263+ }
260264 [ sym:: linkage, ..] => self . check_linkage ( attr, span, target) ,
261265 [ sym:: rustc_pub_transparent, ..] => self . check_rustc_pub_transparent ( attr. span ( ) , span, attrs) ,
262266 [
@@ -2519,6 +2523,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
25192523 }
25202524 }
25212525
2526+ fn check_type_const ( & self , hir_id : HirId , attr : & Attribute , target : Target ) {
2527+ let tcx = self . tcx ;
2528+ if target == Target :: AssocConst
2529+ && let parent = tcx. parent ( hir_id. expect_owner ( ) . to_def_id ( ) )
2530+ && self . tcx . def_kind ( parent) == DefKind :: Trait
2531+ {
2532+ return ;
2533+ } else {
2534+ self . dcx ( )
2535+ . struct_span_err (
2536+ attr. span ( ) ,
2537+ "`#[type_const]` must only be applied to trait associated constants" ,
2538+ )
2539+ . emit ( ) ;
2540+ }
2541+ }
2542+
25222543 fn check_linkage ( & self , attr : & Attribute , span : Span , target : Target ) {
25232544 match target {
25242545 Target :: Fn
0 commit comments