Skip to content

Commit 5387d8b

Browse files
Update rustdoc tests and add test for #[doc(hidden)] re-exports.
1 parent ed49e5c commit 5387d8b

File tree

3 files changed

+122
-33
lines changed

3 files changed

+122
-33
lines changed

tests/rustdoc/doc-hidden-reexports.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Test to enforce rules over re-exports inlining from
2+
// <https://github.com/rust-lang/rust/issues/109449>.
3+
4+
#![crate_name = "foo"]
5+
6+
mod private_module {
7+
#[doc(hidden)]
8+
pub struct Public;
9+
#[doc(hidden)]
10+
pub type Bar = ();
11+
}
12+
13+
#[doc(hidden)]
14+
mod module {
15+
pub struct Public2;
16+
pub type Bar2 = ();
17+
}
18+
19+
#[doc(hidden)]
20+
pub type Bar3 = ();
21+
#[doc(hidden)]
22+
pub struct FooFoo;
23+
24+
// Checking that re-exporting a `#[doc(hidden)]` item will inline it.
25+
pub mod single_reexport {
26+
// @has 'foo/single_reexport/index.html'
27+
28+
// First we check that we have all 6 items: 3 structs and 3 type aliases.
29+
// @count - '//a[@class="struct"]' 3
30+
// @count - '//a[@class="type"]' 3
31+
32+
// Then we check that we have the correct link for each re-export.
33+
34+
// @has - '//*[@href="struct.Foo.html"]' 'Foo'
35+
pub use crate::private_module::Public as Foo;
36+
// @has - '//*[@href="type.Foo2.html"]' 'Foo2'
37+
pub use crate::private_module::Bar as Foo2;
38+
// @has - '//*[@href="type.Yo.html"]' 'Yo'
39+
pub use crate::Bar3 as Yo;
40+
// @has - '//*[@href="struct.Yo2.html"]' 'Yo2'
41+
pub use crate::FooFoo as Yo2;
42+
// @has - '//*[@href="struct.Foo3.html"]' 'Foo3'
43+
pub use crate::module::Public2 as Foo3;
44+
// @has - '//*[@href="type.Foo4.html"]' 'Foo4'
45+
pub use crate::module::Bar2 as Foo4;
46+
47+
// Checking that each file is also created as expected.
48+
// @has 'foo/single_reexport/struct.Foo.html'
49+
// @has 'foo/single_reexport/type.Foo2.html'
50+
// @has 'foo/single_reexport/type.Yo.html'
51+
// @has 'foo/single_reexport/struct.Yo2.html'
52+
// @has 'foo/single_reexport/struct.Foo3.html'
53+
// @has 'foo/single_reexport/type.Foo4.html'
54+
}
55+
56+
// Checking that re-exporting a `#[doc(hidden)]` item with `#[doc(no_inline)]` will not inline
57+
// it but will still display a re-export in the documentation.
58+
pub mod single_reexport_no_inline {
59+
// First we ensure that we only have re-exports and no inlined items.
60+
// @has 'foo/single_reexport_no_inline/index.html'
61+
// @count - '//*[@id="main-content"]/*[@class="small-section-header"]' 1
62+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Re-exports'
63+
64+
// Now we check that we don't have links to the items, just `pub use`.
65+
// @has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Public as XFoo;'
66+
// @!has - '//*[@id="main-content"]//a' 'XFoo'
67+
#[doc(no_inline)]
68+
pub use crate::private_module::Public as XFoo;
69+
// @has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Bar as Foo2;'
70+
// @!has - '//*[@id="main-content"]//a' 'Foo2'
71+
#[doc(no_inline)]
72+
pub use crate::private_module::Bar as Foo2;
73+
// @has - '//*[@id="main-content"]//*' 'pub use crate::Bar3 as Yo;'
74+
// @!has - '//*[@id="main-content"]//a' 'Yo'
75+
#[doc(no_inline)]
76+
pub use crate::Bar3 as Yo;
77+
// @has - '//*[@id="main-content"]//*' 'pub use crate::FooFoo as Yo2;'
78+
// @!has - '//*[@id="main-content"]//a' 'Yo2'
79+
#[doc(no_inline)]
80+
pub use crate::FooFoo as Yo2;
81+
// @has - '//*[@id="main-content"]//*' 'pub use crate::module::Public2 as Foo3;'
82+
// @!has - '//*[@id="main-content"]//a' 'Foo3'
83+
#[doc(no_inline)]
84+
pub use crate::module::Public2 as Foo3;
85+
// @has - '//*[@id="main-content"]//*' 'pub use crate::module::Bar2 as Foo4;'
86+
// @!has - '//*[@id="main-content"]//a' 'Foo4'
87+
#[doc(no_inline)]
88+
pub use crate::module::Bar2 as Foo4;
89+
}
90+
91+
// Checking that glob re-exports don't inline `#[doc(hidden)]` items.
92+
pub mod glob_reexport {
93+
// With glob re-exports, we don't inline `#[doc(hidden)]` items so only `module` items
94+
// should be inlined.
95+
// @has 'foo/glob_reexport/index.html'
96+
// @count - '//*[@id="main-content"]/*[@class="small-section-header"]' 3
97+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Re-exports'
98+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Structs'
99+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Type Definitions'
100+
101+
// Now we check we have 2 re-exports and 2 inlined items.
102+
// @has - '//*[@id="main-content"]//*' 'pub use crate::private_module::*;'
103+
pub use crate::private_module::*;
104+
// @has - '//*[@id="main-content"]//*' 'pub use crate::*;'
105+
pub use crate::*;
106+
// This one should be inlined.
107+
// @!has - '//*[@id="main-content"]//*' 'pub use crate::module::*;'
108+
// @has - '//*[@id="main-content"]//a[@href="struct.Public2.html"]' 'Public2'
109+
// @has - '//*[@id="main-content"]//a[@href="type.Bar2.html"]' 'Bar2'
110+
// And we check that the two files were created too.
111+
// @has 'foo/glob_reexport/struct.Public2.html'
112+
// @has 'foo/glob_reexport/type.Bar2.html'
113+
pub use crate::module::*;
114+
}

tests/rustdoc/reexport-attr-merge.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#![crate_name = "foo"]
66
#![feature(doc_cfg)]
7+
#![feature(no_core)]
8+
#![no_core]
79

810
// @has 'foo/index.html'
911

@@ -20,14 +22,13 @@ pub use Foo1 as Foo2;
2022
// are inlined.
2123
// @count - '//a[@class="struct"]' 2
2224
// Then we check that both `cfg` are displayed.
23-
// @has - '//*[@class="stab portability"]' 'foo'
24-
// @has - '//*[@class="stab portability"]' 'bar'
25+
// @matches - '//*[@class="stab portability"]' '^foo$'
2526
// And finally we check that the only element displayed is `Bar`.
26-
// @has - '//a[@class="struct"]' 'Bar'
27+
// @has - '//a[@href="struct.Bar.html"]' 'Bar'
2728
#[doc(inline)]
28-
pub use Foo2 as Bar;
29+
pub use Foo as Bar;
2930

30-
// This one should appear but `Bar2` won't be linked because there is no
31-
// `#[doc(inline)]`.
32-
// @has - '//*[@id="reexport.Bar2"]' 'pub use Foo2 as Bar2;'
31+
// Re-exported `#[doc(hidden)]` items are inlined as well.
32+
// @has - '//a[@href="struct.Bar2.html"]' 'Bar2'
33+
// @matches - '//*[@class="stab portability"]' '^bar and foo$'
3334
pub use Foo2 as Bar2;

tests/rustdoc/reexport-doc-hidden.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)