@@ -1013,7 +1013,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
1013
1013
tcx : TyCtxt < ' _ > ,
1014
1014
hidden_cfg : & FxHashSet < Cfg > ,
1015
1015
) -> Option < Arc < Cfg > > {
1016
- let sess = tcx. sess ;
1017
1016
let doc_cfg_active = tcx. features ( ) . doc_cfg ( ) ;
1018
1017
let doc_auto_cfg_active = tcx. features ( ) . doc_auto_cfg ( ) ;
1019
1018
@@ -1034,9 +1033,27 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
1034
1033
. filter ( |attr| attr. has_name ( sym:: cfg) )
1035
1034
. peekable ( ) ;
1036
1035
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
+ } )
1040
1057
} else if doc_auto_cfg_active {
1041
1058
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
1042
1059
// `doc(cfg())` overrides `cfg()`).
@@ -1053,40 +1070,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
1053
1070
Cfg :: True
1054
1071
} ;
1055
1072
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
-
1090
1073
// treat #[target_feature(enable = "feat")] attributes as if they were
1091
1074
// #[doc(cfg(target_feature = "feat"))] attributes as well
1092
1075
for attr in hir_attr_lists ( attrs, sym:: target_feature) {
0 commit comments