@@ -11,6 +11,7 @@ use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, as
11
11
use rustc_data_structures:: fx:: FxHashMap ;
12
12
use rustc_errors:: { Applicability , DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
13
13
use rustc_feature:: { AttributeDuplicates , AttributeType , BUILTIN_ATTRIBUTE_MAP , BuiltinAttribute } ;
14
+ use rustc_hir:: def:: DefKind ;
14
15
use rustc_hir:: def_id:: LocalModDefId ;
15
16
use rustc_hir:: intravisit:: { self , Visitor } ;
16
17
use rustc_hir:: {
@@ -247,6 +248,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
247
248
[ sym:: coroutine, ..] => {
248
249
self . check_coroutine ( attr, target) ;
249
250
}
251
+ [ sym:: type_const, ..] => {
252
+ self . check_type_const ( hir_id, attr, target) ;
253
+ }
250
254
[ sym:: linkage, ..] => self . check_linkage ( attr, span, target) ,
251
255
[ sym:: rustc_pub_transparent, ..] => self . check_rustc_pub_transparent ( attr. span , span, attrs) ,
252
256
[
@@ -2493,6 +2497,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2493
2497
}
2494
2498
}
2495
2499
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
+
2496
2517
fn check_linkage ( & self , attr : & Attribute , span : Span , target : Target ) {
2497
2518
match target {
2498
2519
Target :: Fn
0 commit comments