Skip to content

Commit caec4a2

Browse files
committedJan 20, 2022
Extra cfg_hide a bit to handle inner cfgs
1 parent fd005f5 commit caec4a2

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed
 

‎src/librustdoc/clean/cfg.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::mem;
88
use std::ops;
99

1010
use rustc_ast::{LitKind, MetaItem, MetaItemKind, NestedMetaItem};
11+
use rustc_data_structures::fx::FxHashSet;
1112
use rustc_feature::Features;
1213
use rustc_session::parse::ParseSess;
1314
use rustc_span::symbol::{sym, Symbol};
@@ -45,7 +46,7 @@ impl Cfg {
4546
/// Parses a `NestedMetaItem` into a `Cfg`.
4647
fn parse_nested(
4748
nested_cfg: &NestedMetaItem,
48-
exclude: &[Symbol],
49+
exclude: &FxHashSet<Cfg>,
4950
) -> Result<Option<Cfg>, InvalidCfgError> {
5051
match nested_cfg {
5152
NestedMetaItem::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
@@ -57,7 +58,7 @@ impl Cfg {
5758

5859
crate fn parse_without(
5960
cfg: &MetaItem,
60-
exclude: &[Symbol],
61+
exclude: &FxHashSet<Cfg>,
6162
) -> Result<Option<Cfg>, InvalidCfgError> {
6263
let name = match cfg.ident() {
6364
Some(ident) => ident.name,
@@ -70,19 +71,13 @@ impl Cfg {
7071
};
7172
match cfg.kind {
7273
MetaItemKind::Word => {
73-
if exclude.contains(&name) {
74-
Ok(None)
75-
} else {
76-
Ok(Some(Cfg::Cfg(name, None)))
77-
}
74+
let cfg = Cfg::Cfg(name, None);
75+
if exclude.contains(&cfg) { Ok(None) } else { Ok(Some(cfg)) }
7876
}
7977
MetaItemKind::NameValue(ref lit) => match lit.kind {
8078
LitKind::Str(value, _) => {
81-
if exclude.contains(&name) {
82-
Ok(None)
83-
} else {
84-
Ok(Some(Cfg::Cfg(name, Some(value))))
85-
}
79+
let cfg = Cfg::Cfg(name, Some(value));
80+
if exclude.contains(&cfg) { Ok(None) } else { Ok(Some(cfg)) }
8681
}
8782
_ => Err(InvalidCfgError {
8883
// FIXME: if the main #[cfg] syntax decided to support non-string literals,
@@ -126,7 +121,7 @@ impl Cfg {
126121
/// If the content is not properly formatted, it will return an error indicating what and where
127122
/// the error is.
128123
crate fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
129-
Self::parse_without(cfg, &[]).map(|ret| ret.unwrap())
124+
Self::parse_without(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
130125
}
131126

132127
/// Checks whether the given configuration can be matched in the current session.

‎src/librustdoc/clean/types.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,10 @@ impl AttributesExt for [ast::Attribute] {
831831
self.iter()
832832
.filter(|attr| attr.has_name(sym::cfg))
833833
.filter_map(|attr| single(attr.meta_item_list()?))
834-
.filter_map(|attr| match Cfg::parse_without(attr.meta_item()?, &[sym::test]) {
834+
.filter_map(|attr| match Cfg::parse_without(attr.meta_item()?, hidden_cfg) {
835835
Ok(Some(c)) => Some(c),
836836
_ => None,
837837
})
838-
.filter(|cfg| !hidden_cfg.contains(cfg))
839838
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
840839
} else {
841840
Cfg::True

‎src/librustdoc/visit_ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
141141
})
142142
.collect::<Vec<_>>()
143143
})
144+
.chain([Cfg::Cfg(sym::test, None)].into_iter())
144145
.collect();
145146

146147
self.cx.cache.exact_paths = self.exact_paths;

‎src/test/rustdoc/doc-cfg-hide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Hyperdulia;
2626

2727
// @has 'oud/struct.Oystercatcher.html'
2828
// @count - '//*[@class="stab portability"]' 1
29-
// @matches - '//*[@class="stab portability"]' 'crate features solecism and oystercatcher'
29+
// @matches - '//*[@class="stab portability"]' 'crate feature oystercatcher only'
3030
// compile-flags:--cfg feature="oystercatcher"
3131
#[cfg(all(feature = "solecism", feature = "oystercatcher"))]
3232
pub struct Oystercatcher;

0 commit comments

Comments
 (0)
Please sign in to comment.