Skip to content

Commit dac37af

Browse files
authored
Unrolled build for rust-lang#120548
Rollup merge of rust-lang#120548 - GuillaumeGomez:glob-reexport-cfg-merge, r=GuillaumeGomez rustdoc: Fix handling of doc_auto_cfg feature for cfg attributes on glob reexport This is a follow-up of rust-lang#120501 and a part of rust-lang#120487. r? `@notriddle`
2 parents eaff1af + 7c32908 commit dac37af

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

Diff for: src/doc/rustdoc/src/write-documentation/re-exports.md

+29
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,32 @@ There are a few attributes which are not inlined though:
170170

171171
All other attributes are inherited when inlined, so that the documentation matches the behavior if
172172
the inlined item was directly defined at the spot where it's shown.
173+
174+
These rules also apply if the item is inlined with a glob re-export:
175+
176+
```rust,ignore (inline)
177+
mod private_mod {
178+
/// First
179+
#[cfg(a)]
180+
pub struct InPrivate;
181+
}
182+
183+
#[cfg(c)]
184+
pub use self::private_mod::*;
185+
```
186+
187+
Otherwise, the attributes displayed will be from the re-exported item and the attributes on the
188+
re-export itself will be ignored:
189+
190+
```rust,ignore (inline)
191+
mod private_mod {
192+
/// First
193+
#[cfg(a)]
194+
pub struct InPrivate;
195+
}
196+
197+
#[cfg(c)]
198+
pub use self::private_mod::InPrivate;
199+
```
200+
201+
In the above case, `cfg(c)` will not be displayed in the docs.

Diff for: src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2736,7 +2736,7 @@ fn add_without_unwanted_attributes<'hir>(
27362736
if ident == sym::doc {
27372737
filter_doc_attr(normal, is_inline);
27382738
attrs.push((Cow::Owned(attr), import_parent));
2739-
} else if ident != sym::cfg {
2739+
} else if is_inline || ident != sym::cfg {
27402740
// If it's not a `cfg()` attribute, we keep it.
27412741
attrs.push((Cow::Owned(attr), import_parent));
27422742
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This test ensures that non-glob reexports don't get their attributes merge with
2+
// the reexported item whereas glob reexports do with the `doc_auto_cfg` feature.
3+
4+
#![crate_name = "foo"]
5+
#![feature(doc_auto_cfg)]
6+
7+
// @has 'foo/index.html'
8+
// There are two items.
9+
// @count - '//*[@class="item-table"]//div[@class="item-name"]' 2
10+
// Only one of them should have an attribute.
11+
// @count - '//*[@class="item-table"]//div[@class="item-name"]/*[@class="stab portability"]' 1
12+
13+
mod a {
14+
#[cfg(not(feature = "a"))]
15+
pub struct Test1;
16+
}
17+
18+
mod b {
19+
#[cfg(not(feature = "a"))]
20+
pub struct Test2;
21+
}
22+
23+
// @has 'foo/struct.Test1.html'
24+
// @count - '//*[@id="main-content"]/*[@class="item-info"]' 1
25+
// @has - '//*[@id="main-content"]/*[@class="item-info"]' 'Available on non-crate feature a only.'
26+
pub use a::*;
27+
// @has 'foo/struct.Test2.html'
28+
// @count - '//*[@id="main-content"]/*[@class="item-info"]' 0
29+
pub use b::Test2;

0 commit comments

Comments
 (0)