@@ -1013,7 +1013,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10131013 tcx : TyCtxt < ' _ > ,
10141014 hidden_cfg : & FxHashSet < Cfg > ,
10151015) -> Option < Arc < Cfg > > {
1016- let sess = tcx. sess ;
10171016 let doc_cfg_active = tcx. features ( ) . doc_cfg ( ) ;
10181017 let doc_auto_cfg_active = tcx. features ( ) . doc_auto_cfg ( ) ;
10191018
@@ -1034,9 +1033,27 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10341033 . filter ( |attr| attr. has_name ( sym:: cfg) )
10351034 . peekable ( ) ;
10361035 if doc_cfg. peek ( ) . is_some ( ) && doc_cfg_active {
1037- doc_cfg
1038- . filter_map ( |attr| Cfg :: parse ( & attr) . ok ( ) )
1039- . fold ( Cfg :: True , |cfg, new_cfg| cfg & new_cfg)
1036+ let sess = tcx. sess ;
1037+ doc_cfg. fold ( Cfg :: True , |mut cfg, item| {
1038+ if let Some ( cfg_mi) =
1039+ item. meta_item ( ) . and_then ( |item| rustc_expand:: config:: parse_cfg ( item, sess) )
1040+ {
1041+ // The result is unused here but we can gate unstable predicates
1042+ rustc_attr_parsing:: cfg_matches (
1043+ cfg_mi,
1044+ tcx. sess ,
1045+ rustc_ast:: CRATE_NODE_ID ,
1046+ Some ( tcx. features ( ) ) ,
1047+ ) ;
1048+ match Cfg :: parse ( cfg_mi) {
1049+ Ok ( new_cfg) => cfg &= new_cfg,
1050+ Err ( e) => {
1051+ sess. dcx ( ) . span_err ( e. span , e. msg ) ;
1052+ }
1053+ }
1054+ }
1055+ cfg
1056+ } )
10401057 } else if doc_auto_cfg_active {
10411058 // If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
10421059 // `doc(cfg())` overrides `cfg()`).
@@ -1053,40 +1070,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10531070 Cfg :: True
10541071 } ;
10551072
1056- for attr in attrs. clone ( ) {
1057- // #[doc]
1058- if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
1059- // #[doc(...)]
1060- if let Some ( list) = attr. meta_item_list ( ) {
1061- for item in list {
1062- // #[doc(hidden)]
1063- if !item. has_name ( sym:: cfg) {
1064- continue ;
1065- }
1066- // #[doc(cfg(...))]
1067- if let Some ( cfg_mi) = item
1068- . meta_item ( )
1069- . and_then ( |item| rustc_expand:: config:: parse_cfg ( item, sess) )
1070- {
1071- // The result is unused here but we can gate unstable predicates
1072- rustc_attr_parsing:: cfg_matches (
1073- cfg_mi,
1074- tcx. sess ,
1075- rustc_ast:: CRATE_NODE_ID ,
1076- Some ( tcx. features ( ) ) ,
1077- ) ;
1078- match Cfg :: parse ( cfg_mi) {
1079- Ok ( new_cfg) => cfg &= new_cfg,
1080- Err ( e) => {
1081- sess. dcx ( ) . span_err ( e. span , e. msg ) ;
1082- }
1083- }
1084- }
1085- }
1086- }
1087- }
1088- }
1089-
10901073 // treat #[target_feature(enable = "feat")] attributes as if they were
10911074 // #[doc(cfg(target_feature = "feat"))] attributes as well
10921075 for attr in hir_attr_lists ( attrs, sym:: target_feature) {
0 commit comments