Skip to content

Commit 9e6848b

Browse files
Remove duplicated loop when computing doc cfgs
1 parent 75530e9 commit 9e6848b

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

src/librustdoc/clean/types.rs

+14-31
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10041004
tcx: TyCtxt<'_>,
10051005
hidden_cfg: &FxHashSet<Cfg>,
10061006
) -> Option<Arc<Cfg>> {
1007-
let sess = tcx.sess;
10081007
let doc_cfg_active = tcx.features().doc_cfg();
10091008
let doc_auto_cfg_active = tcx.features().doc_auto_cfg();
10101009

@@ -1025,9 +1024,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10251024
.filter(|attr| attr.has_name(sym::cfg))
10261025
.peekable();
10271026
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+
})
10311041
} else if doc_auto_cfg_active {
10321042
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
10331043
// `doc(cfg())` overrides `cfg()`).
@@ -1044,33 +1054,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10441054
Cfg::True
10451055
};
10461056

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-
10741057
// treat #[target_feature(enable = "feat")] attributes as if they were
10751058
// #[doc(cfg(target_feature = "feat"))] attributes as well
10761059
for attr in hir_attr_lists(attrs, sym::target_feature) {

0 commit comments

Comments
 (0)