about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-08-26 16:03:12 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-09-27 11:29:50 +0200
commit77885fef2cd9a7f9daa4f95336f0cfdeb62b3016 (patch)
tree65d6fa476ea49bafef412323035fb7b0e8f11906
parentef8b2a26caccba46584e4753c3091218d4a2e17d (diff)
downloadrust-77885fef2cd9a7f9daa4f95336f0cfdeb62b3016.tar.gz
rust-77885fef2cd9a7f9daa4f95336f0cfdeb62b3016.zip
Improve code comments and extend tests for `doc_cfg` feature
-rw-r--r--src/librustdoc/clean/types.rs6
-rw-r--r--tests/rustdoc-ui/doc-cfg.rs2
-rw-r--r--tests/rustdoc-ui/doc-cfg.stderr14
-rw-r--r--tests/rustdoc/doc_auto_cfg_reexports.rs13
4 files changed, 32 insertions, 3 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index c8e9f3dc479..8b8cf19d8e4 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -925,7 +925,8 @@ pub(crate) fn hir_attr_lists<'a, I: IntoIterator<Item = &'a hir::Attribute>>(
 /// This type keeps track of (doc) cfg information as we go down the item tree.
 #[derive(Clone, Debug)]
 pub(crate) struct CfgInfo {
-    /// List of `doc(auto_cfg(hide(...)))` cfgs.
+    /// List of currently active `doc(auto_cfg(hide(...)))` cfgs,minus currently active
+    /// `doc(auto_cfg(show(...)))` cfgs.
     hidden_cfg: FxHashSet<Cfg>,
     /// Current computed `cfg`. Each time we enter a new item, this field is updated as well while
     /// taking into account the `hidden_cfg` information.
@@ -1181,7 +1182,8 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
             Some(Arc::new(cfg_info.current_cfg.clone()))
         }
     } else {
-        // Since we always want to collect all `cfg` items, we remove the hidden ones afterward.
+        // If `doc(auto_cfg)` feature is enabled, we want to collect all `cfg` items, we remove the
+        // hidden ones afterward.
         match cfg_info.current_cfg.strip_hidden(&cfg_info.hidden_cfg) {
             None | Some(Cfg::True) => None,
             Some(cfg) => Some(Arc::new(cfg)),
diff --git a/tests/rustdoc-ui/doc-cfg.rs b/tests/rustdoc-ui/doc-cfg.rs
index 9840c305290..d72643e2355 100644
--- a/tests/rustdoc-ui/doc-cfg.rs
+++ b/tests/rustdoc-ui/doc-cfg.rs
@@ -13,6 +13,8 @@
 #[doc(auto_cfg(hide(42)))] //~ ERROR
 #[doc(auto_cfg(hide("a")))] //~ ERROR
 #[doc(auto_cfg(hide(foo::bar)))] //~ ERROR
+#[doc(auto_cfg = 42)] //~ ERROR
+#[doc(auto_cfg = "a")] //~ ERROR
 // Shouldn't lint
 #[doc(auto_cfg(hide(windows)))]
 #[doc(auto_cfg(hide(feature = "windows")))]
diff --git a/tests/rustdoc-ui/doc-cfg.stderr b/tests/rustdoc-ui/doc-cfg.stderr
index 36ca18eed8f..13f62e50d90 100644
--- a/tests/rustdoc-ui/doc-cfg.stderr
+++ b/tests/rustdoc-ui/doc-cfg.stderr
@@ -30,6 +30,18 @@ error: `#![doc(auto_cfg(hide(...)))]` only accepts identifiers or key/value item
 LL | #[doc(auto_cfg(hide(foo::bar)))]
    |                     ^^^^^^^^
 
+error: `expected boolean for #[doc(auto_cfg = ...)]`
+  --> $DIR/doc-cfg.rs:16:7
+   |
+LL | #[doc(auto_cfg = 42)]
+   |       ^^^^^^^^^^^^^
+
+error: `expected boolean for #[doc(auto_cfg = ...)]`
+  --> $DIR/doc-cfg.rs:17:7
+   |
+LL | #[doc(auto_cfg = "a")]
+   |       ^^^^^^^^^^^^^^
+
 warning: unexpected `cfg` condition name: `foo`
   --> $DIR/doc-cfg.rs:6:11
    |
@@ -74,5 +86,5 @@ error: multiple `cfg` predicates are specified
 LL | #[doc(cfg(foo, bar))]
    |                ^^^
 
-error: aborting due to 9 previous errors; 2 warnings emitted
+error: aborting due to 11 previous errors; 2 warnings emitted
 
diff --git a/tests/rustdoc/doc_auto_cfg_reexports.rs b/tests/rustdoc/doc_auto_cfg_reexports.rs
index f6315e9d49d..ecfe9aabcfe 100644
--- a/tests/rustdoc/doc_auto_cfg_reexports.rs
+++ b/tests/rustdoc/doc_auto_cfg_reexports.rs
@@ -20,3 +20,16 @@ mod x {
 //      'Available on non-crate feature pistache only.'
 #[cfg(not(feature = "pistache"))]
 pub use crate::x::B;
+
+// Now checking that `cfg`s are not applied on non-inlined reexports.
+pub mod pub_sub_mod {
+    //@ has 'foo/pub_sub_mod/index.html'
+    // There should be only only item with `cfg` note.
+    //@ count - '//*[@class="stab portability"]' 1
+    // And obviously the item should be "blabla".
+    //@ has - '//dt' 'blablaNon-pistache'
+    #[cfg(not(feature = "pistache"))]
+    pub fn blabla() {}
+
+    pub use self::blabla as another;
+}