Remove duplicated loop when computing doc cfgs · rust-lang/rust@9e6848b (original) (raw)
`@@ -1004,7 +1004,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
`
1004
1004
`tcx: TyCtxt<'_>,
`
1005
1005
`hidden_cfg: &FxHashSet,
`
1006
1006
`) -> Option<Arc> {
`
1007
``
`-
let sess = tcx.sess;
`
1008
1007
`let doc_cfg_active = tcx.features().doc_cfg();
`
1009
1008
`let doc_auto_cfg_active = tcx.features().doc_auto_cfg();
`
1010
1009
``
`@@ -1025,9 +1024,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
`
1025
1024
`.filter(|attr| attr.has_name(sym::cfg))
`
1026
1025
`.peekable();
`
1027
1026
`if doc_cfg.peek().is_some() && doc_cfg_active {
`
1028
``
`-
doc_cfg
`
1029
``
`-
.filter_map(|attr| Cfg::parse(&attr).ok())
`
1030
``
`-
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
`
``
1027
`+
let sess = tcx.sess;
`
``
1028
`+
doc_cfg.fold(Cfg::True, |mut cfg, item| {
`
``
1029
`+
if let Some(cfg_mi) =
`
``
1030
`+
item.meta_item().and_then(|item| rustc_expand::config::parse_cfg(item, sess))
`
``
1031
`+
{
`
``
1032
`+
match Cfg::parse(cfg_mi) {
`
``
1033
`+
Ok(new_cfg) => cfg &= new_cfg,
`
``
1034
`+
Err(e) => {
`
``
1035
`+
sess.dcx().span_err(e.span, e.msg);
`
``
1036
`+
}
`
``
1037
`+
}
`
``
1038
`+
}
`
``
1039
`+
cfg
`
``
1040
`+
})
`
1031
1041
`} else if doc_auto_cfg_active {
`
1032
1042
`` // If there is no doc(cfg())
, then we retrieve the cfg()
attributes (because
``
1033
1043
`` // doc(cfg())
overrides cfg()
).
``
`@@ -1044,33 +1054,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
`
1044
1054
`Cfg::True
`
1045
1055
`};
`
1046
1056
``
1047
``
`-
for attr in attrs.clone() {
`
1048
``
`-
// #[doc]
`
1049
``
`-
if attr.doc_str().is_none() && attr.has_name(sym::doc) {
`
1050
``
`-
// #[doc(...)]
`
1051
``
`-
if let Some(list) = attr.meta_item_list() {
`
1052
``
`-
for item in list {
`
1053
``
`-
// #[doc(hidden)]
`
1054
``
`-
if !item.has_name(sym::cfg) {
`
1055
``
`-
continue;
`
1056
``
`-
}
`
1057
``
`-
// #[doc(cfg(...))]
`
1058
``
`-
if let Some(cfg_mi) = item
`
1059
``
`-
.meta_item()
`
1060
``
`-
.and_then(|item| rustc_expand::config::parse_cfg(item, sess))
`
1061
``
`-
{
`
1062
``
`-
match Cfg::parse(cfg_mi) {
`
1063
``
`-
Ok(new_cfg) => cfg &= new_cfg,
`
1064
``
`-
Err(e) => {
`
1065
``
`-
sess.dcx().span_err(e.span, e.msg);
`
1066
``
`-
}
`
1067
``
`-
}
`
1068
``
`-
}
`
1069
``
`-
}
`
1070
``
`-
}
`
1071
``
`-
}
`
1072
``
`-
}
`
1073
``
-
1074
1057
`// treat #[target_feature(enable = "feat")] attributes as if they were
`
1075
1058
`// #[doc(cfg(target_feature = "feat"))] attributes as well
`
1076
1059
`for attr in hir_attr_lists(attrs, sym::target_feature) {
`