about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-01-16 21:03:16 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2022-01-20 22:05:26 +0100
commitcaec4a23f201ff4e2bbfc3f8fd8b97e5e64fc20d (patch)
tree4753d4ed25f5af7af392f7d06bb3b7e893055ef4
parentfd005f53c204136732c446dc476afc1266de730b (diff)
downloadrust-caec4a23f201ff4e2bbfc3f8fd8b97e5e64fc20d.tar.gz
rust-caec4a23f201ff4e2bbfc3f8fd8b97e5e64fc20d.zip
Extra cfg_hide a bit to handle inner cfgs
-rw-r--r--src/librustdoc/clean/cfg.rs21
-rw-r--r--src/librustdoc/clean/types.rs3
-rw-r--r--src/librustdoc/visit_ast.rs1
-rw-r--r--src/test/rustdoc/doc-cfg-hide.rs2
4 files changed, 11 insertions, 16 deletions
diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs
index 2c1dcad1afc..afa02f1e5c7 100644
--- a/src/librustdoc/clean/cfg.rs
+++ b/src/librustdoc/clean/cfg.rs
@@ -8,6 +8,7 @@ use std::mem;
 use std::ops;
 
 use rustc_ast::{LitKind, MetaItem, MetaItemKind, NestedMetaItem};
+use rustc_data_structures::fx::FxHashSet;
 use rustc_feature::Features;
 use rustc_session::parse::ParseSess;
 use rustc_span::symbol::{sym, Symbol};
@@ -45,7 +46,7 @@ impl Cfg {
     /// Parses a `NestedMetaItem` into a `Cfg`.
     fn parse_nested(
         nested_cfg: &NestedMetaItem,
-        exclude: &[Symbol],
+        exclude: &FxHashSet<Cfg>,
     ) -> Result<Option<Cfg>, InvalidCfgError> {
         match nested_cfg {
             NestedMetaItem::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
@@ -57,7 +58,7 @@ impl Cfg {
 
     crate fn parse_without(
         cfg: &MetaItem,
-        exclude: &[Symbol],
+        exclude: &FxHashSet<Cfg>,
     ) -> Result<Option<Cfg>, InvalidCfgError> {
         let name = match cfg.ident() {
             Some(ident) => ident.name,
@@ -70,19 +71,13 @@ impl Cfg {
         };
         match cfg.kind {
             MetaItemKind::Word => {
-                if exclude.contains(&name) {
-                    Ok(None)
-                } else {
-                    Ok(Some(Cfg::Cfg(name, None)))
-                }
+                let cfg = Cfg::Cfg(name, None);
+                if exclude.contains(&cfg) { Ok(None) } else { Ok(Some(cfg)) }
             }
             MetaItemKind::NameValue(ref lit) => match lit.kind {
                 LitKind::Str(value, _) => {
-                    if exclude.contains(&name) {
-                        Ok(None)
-                    } else {
-                        Ok(Some(Cfg::Cfg(name, Some(value))))
-                    }
+                    let cfg = Cfg::Cfg(name, Some(value));
+                    if exclude.contains(&cfg) { Ok(None) } else { Ok(Some(cfg)) }
                 }
                 _ => Err(InvalidCfgError {
                     // FIXME: if the main #[cfg] syntax decided to support non-string literals,
@@ -126,7 +121,7 @@ impl Cfg {
     /// If the content is not properly formatted, it will return an error indicating what and where
     /// the error is.
     crate fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
-        Self::parse_without(cfg, &[]).map(|ret| ret.unwrap())
+        Self::parse_without(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
     }
 
     /// Checks whether the given configuration can be matched in the current session.
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 347f9d0a47c..92e8b893115 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -831,11 +831,10 @@ impl AttributesExt for [ast::Attribute] {
                 self.iter()
                     .filter(|attr| attr.has_name(sym::cfg))
                     .filter_map(|attr| single(attr.meta_item_list()?))
-                    .filter_map(|attr| match Cfg::parse_without(attr.meta_item()?, &[sym::test]) {
+                    .filter_map(|attr| match Cfg::parse_without(attr.meta_item()?, hidden_cfg) {
                         Ok(Some(c)) => Some(c),
                         _ => None,
                     })
-                    .filter(|cfg| !hidden_cfg.contains(cfg))
                     .fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
             } else {
                 Cfg::True
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 90cb5d586c2..2cbb3324a5e 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -141,6 +141,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     })
                     .collect::<Vec<_>>()
             })
+            .chain([Cfg::Cfg(sym::test, None)].into_iter())
             .collect();
 
         self.cx.cache.exact_paths = self.exact_paths;
diff --git a/src/test/rustdoc/doc-cfg-hide.rs b/src/test/rustdoc/doc-cfg-hide.rs
index 424fa6d6a91..636957fe998 100644
--- a/src/test/rustdoc/doc-cfg-hide.rs
+++ b/src/test/rustdoc/doc-cfg-hide.rs
@@ -26,7 +26,7 @@ pub struct Hyperdulia;
 
 // @has 'oud/struct.Oystercatcher.html'
 // @count   - '//*[@class="stab portability"]' 1
-// @matches - '//*[@class="stab portability"]' 'crate features solecism and oystercatcher'
+// @matches - '//*[@class="stab portability"]' 'crate feature oystercatcher only'
 // compile-flags:--cfg feature="oystercatcher"
 #[cfg(all(feature = "solecism", feature = "oystercatcher"))]
 pub struct Oystercatcher;