Skip to content

Commit 1f5a5a2

Browse files
committed
rustdoc: correctly propagate cfgs for glob reexports
* rustdoc: correctly propagate cfgs for glob reexports * address review feedback, add a comment explaining the test * empty commit to trigger CI * empty commit to trigger CI * fix sorting of features in tests * assert contents of index.html
1 parent dc375db commit 1f5a5a2

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ fn generate_item_with_correct_attrs(
243243
) || (is_glob_import(tcx, import_id)
244244
&& (cx.document_hidden() || !tcx.is_doc_hidden(def_id)))
245245
|| macro_reexport_is_inline(tcx, import_id, def_id);
246-
attrs.extend(get_all_import_attributes(cx, import_id, def_id, is_inline));
247246
is_inline = is_inline || import_is_inline;
247+
attrs.extend(get_all_import_attributes(cx, import_id, def_id, is_inline));
248248
}
249249
let keep_target_cfg = is_inline || matches!(kind, ItemKind::TypeAliasItem(..));
250250
add_without_unwanted_attributes(&mut attrs, target_attrs, keep_target_cfg, None);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This test ensures that `cfg`s are correctly propagated for re-export chains
2+
// where the outermost is a glob re-export.
3+
4+
#![crate_name = "foo"]
5+
#![feature(doc_cfg)]
6+
7+
//@ has 'foo/index.html'
8+
//@ count - '//*[@class="item-table"]/dt' 3
9+
10+
//@ has 'foo/index.html'
11+
//@ has - '//dt/a[@title="struct foo::A"]/../*[@class="stab portability"]' 'Non-bar and non-foo'
12+
13+
//@ has 'foo/struct.A.html'
14+
//@ has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
15+
// 'Available on non-crate feature bar and non-crate feature foo only.'
16+
17+
mod a {
18+
mod inner {
19+
pub struct A {}
20+
}
21+
#[cfg(not(feature = "bar"))]
22+
pub use self::inner::A;
23+
}
24+
#[cfg(not(feature = "foo"))]
25+
pub use a::*;
26+
27+
//@ has 'foo/index.html'
28+
//@ has - '//dt/a[@title="struct foo::B"]/../*[@class="stab portability"]' 'Non-bar and non-baz and non-foo'
29+
30+
//@ has 'foo/struct.B.html'
31+
//@ has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
32+
// 'Available on non-crate feature bar and non-crate feature baz and non-crate feature foo only.'
33+
34+
mod b {
35+
mod inner {
36+
mod innermost {
37+
pub struct B {}
38+
}
39+
#[cfg(not(feature = "baz"))]
40+
pub use self::innermost::B;
41+
}
42+
#[cfg(not(feature = "bar"))]
43+
pub use self::inner::*;
44+
}
45+
#[cfg(not(feature = "foo"))]
46+
pub use b::*;
47+
48+
//@ has 'foo/index.html'
49+
//@ has - '//dt/a[@title="struct foo::C"]/../*[@class="stab portability"]' 'Non-bar and non-baz and non-foo'
50+
51+
//@ has 'foo/struct.C.html'
52+
//@ has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
53+
// 'Available on non-crate feature bar and non-crate feature baz and non-crate feature foo only.'
54+
55+
mod c {
56+
mod inner {
57+
mod innermost {
58+
#[cfg(not(feature = "baz"))]
59+
pub struct C {}
60+
}
61+
pub use self::innermost::*;
62+
}
63+
#[cfg(not(feature = "bar"))]
64+
pub use self::inner::*;
65+
}
66+
#[cfg(not(feature = "foo"))]
67+
pub use c::*;

0 commit comments

Comments
 (0)