Rollup merge of #138755 - GuillaumeGomez:rm-duplicated-loop, r=camelid
[rustdoc] Remove duplicated loop when computing doc cfgs Working on implementing https://github.com/rust-lang/rfcs/blob/master/text/3631-rustdoc-cfgs-handling.md and found this weird case where the first loop was actually not doing anything since we were passing `cfg(...)` to `Cfg::parse` instead of `cfg(...)` items. Well, that should be a first nice cleanup before the rest comes in. cc ```@notriddle``` r? ```@camelid```
This commit is contained in:
commit
07d0963c5f
1 changed files with 21 additions and 38 deletions
|
@ -1013,7 +1013,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
hidden_cfg: &FxHashSet<Cfg>,
|
hidden_cfg: &FxHashSet<Cfg>,
|
||||||
) -> Option<Arc<Cfg>> {
|
) -> Option<Arc<Cfg>> {
|
||||||
let sess = tcx.sess;
|
|
||||||
let doc_cfg_active = tcx.features().doc_cfg();
|
let doc_cfg_active = tcx.features().doc_cfg();
|
||||||
let doc_auto_cfg_active = tcx.features().doc_auto_cfg();
|
let doc_auto_cfg_active = tcx.features().doc_auto_cfg();
|
||||||
|
|
||||||
|
@ -1034,9 +1033,27 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
|
||||||
.filter(|attr| attr.has_name(sym::cfg))
|
.filter(|attr| attr.has_name(sym::cfg))
|
||||||
.peekable();
|
.peekable();
|
||||||
if doc_cfg.peek().is_some() && doc_cfg_active {
|
if doc_cfg.peek().is_some() && doc_cfg_active {
|
||||||
doc_cfg
|
let sess = tcx.sess;
|
||||||
.filter_map(|attr| Cfg::parse(&attr).ok())
|
doc_cfg.fold(Cfg::True, |mut cfg, item| {
|
||||||
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
|
if let Some(cfg_mi) =
|
||||||
|
item.meta_item().and_then(|item| rustc_expand::config::parse_cfg(item, sess))
|
||||||
|
{
|
||||||
|
// The result is unused here but we can gate unstable predicates
|
||||||
|
rustc_attr_parsing::cfg_matches(
|
||||||
|
cfg_mi,
|
||||||
|
tcx.sess,
|
||||||
|
rustc_ast::CRATE_NODE_ID,
|
||||||
|
Some(tcx.features()),
|
||||||
|
);
|
||||||
|
match Cfg::parse(cfg_mi) {
|
||||||
|
Ok(new_cfg) => cfg &= new_cfg,
|
||||||
|
Err(e) => {
|
||||||
|
sess.dcx().span_err(e.span, e.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg
|
||||||
|
})
|
||||||
} else if doc_auto_cfg_active {
|
} else if doc_auto_cfg_active {
|
||||||
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
|
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
|
||||||
// `doc(cfg())` overrides `cfg()`).
|
// `doc(cfg())` overrides `cfg()`).
|
||||||
|
@ -1053,40 +1070,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
|
||||||
Cfg::True
|
Cfg::True
|
||||||
};
|
};
|
||||||
|
|
||||||
for attr in attrs.clone() {
|
|
||||||
// #[doc]
|
|
||||||
if attr.doc_str().is_none() && attr.has_name(sym::doc) {
|
|
||||||
// #[doc(...)]
|
|
||||||
if let Some(list) = attr.meta_item_list() {
|
|
||||||
for item in list {
|
|
||||||
// #[doc(hidden)]
|
|
||||||
if !item.has_name(sym::cfg) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// #[doc(cfg(...))]
|
|
||||||
if let Some(cfg_mi) = item
|
|
||||||
.meta_item()
|
|
||||||
.and_then(|item| rustc_expand::config::parse_cfg(item, sess))
|
|
||||||
{
|
|
||||||
// The result is unused here but we can gate unstable predicates
|
|
||||||
rustc_attr_parsing::cfg_matches(
|
|
||||||
cfg_mi,
|
|
||||||
tcx.sess,
|
|
||||||
rustc_ast::CRATE_NODE_ID,
|
|
||||||
Some(tcx.features()),
|
|
||||||
);
|
|
||||||
match Cfg::parse(cfg_mi) {
|
|
||||||
Ok(new_cfg) => cfg &= new_cfg,
|
|
||||||
Err(e) => {
|
|
||||||
sess.dcx().span_err(e.span, e.msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// treat #[target_feature(enable = "feat")] attributes as if they were
|
// treat #[target_feature(enable = "feat")] attributes as if they were
|
||||||
// #[doc(cfg(target_feature = "feat"))] attributes as well
|
// #[doc(cfg(target_feature = "feat"))] attributes as well
|
||||||
for attr in hir_attr_lists(attrs, sym::target_feature) {
|
for attr in hir_attr_lists(attrs, sym::target_feature) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue