about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-09-29 21:37:52 -0400
committerGitHub <noreply@github.com>2025-09-29 21:37:52 -0400
commit745b8f6b746724365c8bb23c0dcec56471c30400 (patch)
treef17b1e32da607c0a1d454ba91846b5203ecb7eb3
parentafd620f5486c6c0681821f0d54a423482668e343 (diff)
parent9119eba24de69902ba421151691d7a294d96fa04 (diff)
downloadrust-745b8f6b746724365c8bb23c0dcec56471c30400.tar.gz
rust-745b8f6b746724365c8bb23c0dcec56471c30400.zip
Rollup merge of #147153 - GuillaumeGomez:doc-propagation-before-stripping-items, r=lolbinarycat
[rustdoc] Move doc cfg propagation pass before items stripping passes

Follow-up of https://github.com/rust-lang/rust/pull/138907.

r? lolbinarycat
-rw-r--r--src/librustdoc/passes/mod.rs4
-rw-r--r--tests/rustdoc-ui/issues/issue-91713.stdout4
-rw-r--r--tests/rustdoc/doc-auto-cfg-public-in-private.rs16
3 files changed, 20 insertions, 4 deletions
diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs
index 475d05b7d0e..f45df8d2d0d 100644
--- a/src/librustdoc/passes/mod.rs
+++ b/src/librustdoc/passes/mod.rs
@@ -77,11 +77,11 @@ pub(crate) enum Condition {
 pub(crate) const PASSES: &[Pass] = &[
     CHECK_DOC_CFG,
     CHECK_DOC_TEST_VISIBILITY,
+    PROPAGATE_DOC_CFG,
     STRIP_ALIASED_NON_LOCAL,
     STRIP_HIDDEN,
     STRIP_PRIVATE,
     STRIP_PRIV_IMPORTS,
-    PROPAGATE_DOC_CFG,
     PROPAGATE_STABILITY,
     COLLECT_INTRA_DOC_LINKS,
     COLLECT_TRAIT_IMPLS,
@@ -94,11 +94,11 @@ pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
     ConditionalPass::always(COLLECT_TRAIT_IMPLS),
     ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
     ConditionalPass::always(CHECK_DOC_CFG),
+    ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
     ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
     ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
     ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
     ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
-    ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
     ConditionalPass::always(PROPAGATE_DOC_CFG),
     ConditionalPass::always(PROPAGATE_STABILITY),
     ConditionalPass::always(RUN_LINTS),
diff --git a/tests/rustdoc-ui/issues/issue-91713.stdout b/tests/rustdoc-ui/issues/issue-91713.stdout
index 30aadfe89f4..d34714be6c9 100644
--- a/tests/rustdoc-ui/issues/issue-91713.stdout
+++ b/tests/rustdoc-ui/issues/issue-91713.stdout
@@ -1,11 +1,11 @@
 Available passes for running rustdoc:
        check-doc-cfg - checks `#[doc(cfg(...))]` for stability feature and unexpected cfgs
 check_doc_test_visibility - run various visibility-related lints on doctests
+   propagate-doc-cfg - propagates `#[doc(cfg(...))]` to child items
 strip-aliased-non-local - strips all non-local private aliased items from the output
         strip-hidden - strips all `#[doc(hidden)]` items from the output
        strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports
   strip-priv-imports - strips all private import statements (`use`, `extern crate`) from a crate
-   propagate-doc-cfg - propagates `#[doc(cfg(...))]` to child items
  propagate-stability - propagates stability to child items
 collect-intra-doc-links - resolves intra-doc links
  collect-trait-impls - retrieves trait impls for items in the crate
@@ -16,11 +16,11 @@ Default passes for rustdoc:
  collect-trait-impls
 check_doc_test_visibility
        check-doc-cfg
+collect-intra-doc-links
 strip-aliased-non-local
         strip-hidden  (when not --document-hidden-items)
        strip-private  (when not --document-private-items)
   strip-priv-imports  (when --document-private-items)
-collect-intra-doc-links
    propagate-doc-cfg
  propagate-stability
            run-lints
diff --git a/tests/rustdoc/doc-auto-cfg-public-in-private.rs b/tests/rustdoc/doc-auto-cfg-public-in-private.rs
new file mode 100644
index 00000000000..b78e3f1b932
--- /dev/null
+++ b/tests/rustdoc/doc-auto-cfg-public-in-private.rs
@@ -0,0 +1,16 @@
+// This test ensures that even though private items are removed from generated docs,
+// their `cfg`s will still impact their child items.
+
+#![feature(doc_cfg)]
+#![crate_name = "foo"]
+
+pub struct X;
+
+#[cfg(not(feature = "blob"))]
+fn foo() {
+    impl X {
+        //@ has 'foo/struct.X.html'
+        //@ has - '//*[@class="stab portability"]' 'Available on non-crate feature blob only.'
+        pub fn bar() {}
+    }
+}