@@ -1202,6 +1202,48 @@ impl<'a> AstValidator<'a> {
12021202 self . visit_vis ( vis) ;
12031203 self . visit_ident ( ident) ;
12041204 }
1205+
1206+ // Check EII implementation attributes against an allowlist.
1207+ fn check_eii_impl_attrs ( & self , attrs : & [ Attribute ] , eii_impls : & [ EiiImpl ] ) {
1208+ if eii_impls. is_empty ( ) {
1209+ return ;
1210+ }
1211+
1212+ let allowed_attrs: & [ Symbol ] = & [
1213+ sym:: allow,
1214+ sym:: warn,
1215+ sym:: deny,
1216+ sym:: forbid,
1217+ sym:: expect,
1218+ sym:: doc,
1219+ sym:: inline,
1220+ sym:: cold,
1221+ sym:: optimize,
1222+ sym:: coverage,
1223+ sym:: sanitize,
1224+ sym:: must_use,
1225+ sym:: deprecated,
1226+ ] ;
1227+
1228+ for attr in attrs {
1229+ let AttrKind :: Normal ( normal) = & attr. kind else {
1230+ continue ;
1231+ } ;
1232+ if attr. has_any_name ( allowed_attrs) {
1233+ continue ;
1234+ }
1235+
1236+ let attr_name = pprust:: path_to_string ( & normal. item . path ) ;
1237+ for eii_impl in eii_impls {
1238+ self . dcx ( ) . emit_err ( diagnostics:: EiiImplAttributeNotSupported {
1239+ attr_span : attr. span ,
1240+ attr_name : & attr_name,
1241+ eii_span : eii_impl. span ,
1242+ eii_name : pprust:: path_to_string ( & eii_impl. eii_macro_path ) ,
1243+ } ) ;
1244+ }
1245+ }
1246+ }
12051247}
12061248
12071249/// Checks that generic parameters are in the correct order,
@@ -1391,6 +1433,7 @@ impl Visitor<'_> for AstValidator<'_> {
13911433 for EiiImpl { eii_macro_path, .. } in eii_impls {
13921434 self . visit_path ( eii_macro_path) ;
13931435 }
1436+ self . check_eii_impl_attrs ( & item. attrs , eii_impls) ;
13941437
13951438 let is_intrinsic = item. attrs . iter ( ) . any ( |a| a. has_name ( sym:: rustc_intrinsic) ) ;
13961439 if body. is_none ( ) && !is_intrinsic && !self . is_sdylib_interface {
@@ -1566,8 +1609,9 @@ impl Visitor<'_> for AstValidator<'_> {
15661609
15671610 visit:: walk_item ( self , item) ;
15681611 }
1569- ItemKind :: Static ( StaticItem { expr, safety, .. } ) => {
1612+ ItemKind :: Static ( StaticItem { expr, safety, eii_impls , .. } ) => {
15701613 self . check_item_safety ( item. span , * safety) ;
1614+ self . check_eii_impl_attrs ( & item. attrs , eii_impls) ;
15711615 if matches ! ( safety, Safety :: Unsafe ( _) ) {
15721616 self . dcx ( ) . emit_err ( diagnostics:: UnsafeStatic { span : item. span } ) ;
15731617 }
0 commit comments