@@ -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:: {
@@ -246,6 +247,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
246
247
[ sym:: coroutine, ..] => {
247
248
self . check_coroutine ( attr, target) ;
248
249
}
250
+ [ sym:: type_const, ..] => {
251
+ self . check_type_const ( hir_id, attr, target) ;
252
+ }
249
253
[ sym:: linkage, ..] => self . check_linkage ( attr, span, target) ,
250
254
[ sym:: rustc_pub_transparent, ..] => self . check_rustc_pub_transparent ( attr. span , span, attrs) ,
251
255
[
@@ -2455,6 +2459,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2455
2459
}
2456
2460
}
2457
2461
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
+
2458
2479
fn check_linkage ( & self , attr : & Attribute , span : Span , target : Target ) {
2459
2480
match target {
2460
2481
Target :: Fn
0 commit comments