about summary refs log tree commit diff
path: root/tests/rustdoc
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-12-15 11:51:23 +0100
committerGitHub <noreply@github.com>2023-12-15 11:51:23 +0100
commitec0008a915c3d27528a2df0eb420aed748b217f8 (patch)
treea56142d8f4e578b4b6064df07c49084271f32387 /tests/rustdoc
parentd253bf61ad38a59cc579aee688f81a06c31283d3 (diff)
parent823148fa849eb9b6fb896a0ac1772a2be3bdb043 (diff)
downloadrust-ec0008a915c3d27528a2df0eb420aed748b217f8.tar.gz
rust-ec0008a915c3d27528a2df0eb420aed748b217f8.zip
Rollup merge of #113091 - GuillaumeGomez:prevent-cfg-merge-reexport, r=rustdoc
Don't merge cfg and doc(cfg) attributes for re-exports

Fixes #112881.

## Explanations

When re-exporting things with different `cfg`s there are two things that can happen:

 * The re-export uses a subset of `cfg`s, this subset is sufficient so that the item will appear exactly with the subset
 * The re-export uses a non-subset of `cfg`s (e.g. like the example I posted just above where the re-export is ungated), if the non-subset `cfg`s are active (e.g. compiling that example on windows) then this will be a compile error as the item doesn't exist to re-export, if the subset `cfg`s are active it behaves like 1.

### Glob re-exports?

**This only applies to non-glob inlined re-exports.** For glob re-exports the item may or may not exist to be re-exported (potentially the `cfg`s on the path up until the glob can be removed, and only `cfg`s on the globbed item itself matter), for non-inlined re-exports see https://github.com/rust-lang/rust/issues/85043.

cc `@Nemo157`
r? `@notriddle`
Diffstat (limited to 'tests/rustdoc')
-rw-r--r--tests/rustdoc/reexport-cfg.rs30
-rw-r--r--tests/rustdoc/reexport-stability-tags-deprecated-and-portability.rs4
-rw-r--r--tests/rustdoc/reexport-stability-tags-unstable-and-portability.rs4
3 files changed, 34 insertions, 4 deletions
diff --git a/tests/rustdoc/reexport-cfg.rs b/tests/rustdoc/reexport-cfg.rs
new file mode 100644
index 00000000000..a6179fad873
--- /dev/null
+++ b/tests/rustdoc/reexport-cfg.rs
@@ -0,0 +1,30 @@
+// This test ensures that only the re-export `cfg` will be displayed and that it won't
+// include `cfg`s from the previous chained items.
+
+#![crate_name = "foo"]
+#![feature(doc_auto_cfg, doc_cfg)]
+
+mod foo {
+    #[cfg(not(feature = "foo"))]
+    pub struct Bar;
+
+    #[doc(cfg(not(feature = "bar")))]
+    pub struct Bar2;
+}
+
+// @has 'foo/index.html'
+// @has - '//*[@class="item-name"]' 'BabarNon-lie'
+#[cfg(not(feature = "lie"))]
+pub use crate::foo::Bar as Babar;
+
+// @has - '//*[@class="item-name"]' 'Babar2Non-cake'
+#[doc(cfg(not(feature = "cake")))]
+pub use crate::foo::Bar2 as Babar2;
+
+// @has - '//*[@class="item-table"]/li' 'pub use crate::Babar as Elephant;Non-robot'
+#[cfg(not(feature = "robot"))]
+pub use crate::Babar as Elephant;
+
+// @has - '//*[@class="item-table"]/li' 'pub use crate::Babar2 as Elephant2;Non-cat'
+#[doc(cfg(not(feature = "cat")))]
+pub use crate::Babar2 as Elephant2;
diff --git a/tests/rustdoc/reexport-stability-tags-deprecated-and-portability.rs b/tests/rustdoc/reexport-stability-tags-deprecated-and-portability.rs
index a79d05904e3..c81c654a20e 100644
--- a/tests/rustdoc/reexport-stability-tags-deprecated-and-portability.rs
+++ b/tests/rustdoc/reexport-stability-tags-deprecated-and-portability.rs
@@ -27,7 +27,7 @@ pub mod mod1 {
 pub mod mod2 {
     // @has - '//code' 'pub use tag::Portability;'
     // @!has - '//span' 'Deprecated'
-    // @has - '//span' 'sync'
+    // @!has - '//span' 'sync'
     pub use tag::Portability;
 }
 
@@ -35,7 +35,7 @@ pub mod mod2 {
 pub mod mod3 {
     // @has - '//code' 'pub use tag::Both;'
     // @has - '//span' 'Deprecated'
-    // @has - '//span' 'sync'
+    // @!has - '//span' 'sync'
     pub use tag::Both;
 }
 
diff --git a/tests/rustdoc/reexport-stability-tags-unstable-and-portability.rs b/tests/rustdoc/reexport-stability-tags-unstable-and-portability.rs
index ff8a910f59f..423838e251b 100644
--- a/tests/rustdoc/reexport-stability-tags-unstable-and-portability.rs
+++ b/tests/rustdoc/reexport-stability-tags-unstable-and-portability.rs
@@ -35,7 +35,7 @@ pub mod mod1 {
 pub mod mod2 {
     // @has - '//code' 'pub use tag::Portability;'
     // @!has - '//span' 'Experimental'
-    // @has - '//span' 'sync'
+    // @!has - '//span' 'sync'
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use tag::Portability;
 }
@@ -45,7 +45,7 @@ pub mod mod2 {
 pub mod mod3 {
     // @has - '//code' 'pub use tag::Both;'
     // @has - '//span' 'Experimental'
-    // @has - '//span' 'sync'
+    // @!has - '//span' 'sync'
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use tag::Both;
 }