@@ -8,7 +8,9 @@ use rustc_ast::tokenstream::{
88use rustc_ast:: { self as ast, AttrStyle , Attribute , HasAttrs , HasTokens , MetaItem , NodeId } ;
99use rustc_attr as attr;
1010use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
11- use rustc_feature:: { Features , ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_FEATURES } ;
11+ use rustc_feature:: {
12+ AttributeSafety , Features , ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_FEATURES ,
13+ } ;
1214use rustc_lint_defs:: BuiltinLintDiag ;
1315use rustc_parse:: validate_attr;
1416use rustc_session:: parse:: feature_err;
@@ -263,6 +265,13 @@ impl<'a> StripUnconfigured<'a> {
263265 /// is in the original source file. Gives a compiler error if the syntax of
264266 /// the attribute is incorrect.
265267 pub ( crate ) fn expand_cfg_attr ( & self , cfg_attr : & Attribute , recursive : bool ) -> Vec < Attribute > {
268+ validate_attr:: check_attribute_safety (
269+ self . features . unwrap_or ( & Features :: default ( ) ) ,
270+ & self . sess . psess ,
271+ AttributeSafety :: Normal ,
272+ & cfg_attr,
273+ ) ;
274+
266275 let Some ( ( cfg_predicate, expanded_attrs) ) =
267276 rustc_parse:: parse_cfg_attr ( cfg_attr, & self . sess . psess )
268277 else {
@@ -385,6 +394,13 @@ impl<'a> StripUnconfigured<'a> {
385394 return ( true , None ) ;
386395 }
387396 } ;
397+
398+ validate_attr:: deny_builtin_meta_unsafety (
399+ self . features . unwrap_or ( & Features :: default ( ) ) ,
400+ & self . sess . psess ,
401+ & meta_item,
402+ ) ;
403+
388404 (
389405 parse_cfg ( & meta_item, self . sess ) . map_or ( true , |meta_item| {
390406 attr:: cfg_matches ( meta_item, & self . sess , self . lint_node_id , self . features )
0 commit comments