Skip to content

Commit bfb4685

Browse files
Improve code comments and extend tests for doc_cfg feature
1 parent 12c142f commit bfb4685

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/librustdoc/clean/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ pub(crate) fn hir_attr_lists<'a, I: IntoIterator<Item = &'a hir::Attribute>>(
10441044
/// This type keeps track of (doc) cfg information as we go down the item tree.
10451045
#[derive(Clone, Debug)]
10461046
pub(crate) struct CfgInfo {
1047-
/// List of `doc(auto_cfg(hide(...)))` cfgs.
1047+
/// List of currently active `doc(auto_cfg(hide(...)))` cfgs,minus currently active
1048+
/// `doc(auto_cfg(show(...)))` cfgs.
10481049
hidden_cfg: FxHashSet<Cfg>,
10491050
/// Current computed `cfg`. Each time we enter a new item, this field is updated as well while
10501051
/// taking into account the `hidden_cfg` information.
@@ -1300,7 +1301,8 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
13001301
Some(Arc::new(cfg_info.current_cfg.clone()))
13011302
}
13021303
} else {
1303-
// Since we always want to collect all `cfg` items, we remove the hidden ones afterward.
1304+
// If `doc(auto_cfg)` feature is enabled, we want to collect all `cfg` items, we remove the
1305+
// hidden ones afterward.
13041306
match cfg_info.current_cfg.strip_hidden(&cfg_info.hidden_cfg) {
13051307
None | Some(Cfg::True) => None,
13061308
Some(cfg) => Some(Arc::new(cfg)),

tests/rustdoc-ui/doc-cfg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#[doc(auto_cfg(hide(42)))] //~ ERROR
1414
#[doc(auto_cfg(hide("a")))] //~ ERROR
1515
#[doc(auto_cfg(hide(foo::bar)))] //~ ERROR
16+
#[doc(auto_cfg = 42)] //~ ERROR
17+
#[doc(auto_cfg = "a")] //~ ERROR
1618
// Shouldn't lint
1719
#[doc(auto_cfg(hide(windows)))]
1820
#[doc(auto_cfg(hide(feature = "windows")))]

tests/rustdoc-ui/doc-cfg.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ error: `#![doc(auto_cfg(hide(...)))]` only accepts identifiers or key/value item
3030
LL | #[doc(auto_cfg(hide(foo::bar)))]
3131
| ^^^^^^^^
3232

33+
error: `expected boolean for #[doc(auto_cfg = ...)]`
34+
--> $DIR/doc-cfg.rs:16:7
35+
|
36+
LL | #[doc(auto_cfg = 42)]
37+
| ^^^^^^^^^^^^^
38+
39+
error: `expected boolean for #[doc(auto_cfg = ...)]`
40+
--> $DIR/doc-cfg.rs:17:7
41+
|
42+
LL | #[doc(auto_cfg = "a")]
43+
| ^^^^^^^^^^^^^^
44+
3345
warning: unexpected `cfg` condition name: `foo`
3446
--> $DIR/doc-cfg.rs:6:11
3547
|
@@ -74,5 +86,5 @@ error: multiple `cfg` predicates are specified
7486
LL | #[doc(cfg(foo, bar))]
7587
| ^^^
7688

77-
error: aborting due to 9 previous errors; 2 warnings emitted
89+
error: aborting due to 11 previous errors; 2 warnings emitted
7890

tests/rustdoc/doc_auto_cfg_reexports.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ mod x {
2020
// 'Available on non-crate feature pistache only.'
2121
#[cfg(not(feature = "pistache"))]
2222
pub use crate::x::B;
23+
24+
// Now checking that `cfg`s are not applied on non-inlined reexports.
25+
pub mod pub_sub_mod {
26+
//@ has 'foo/pub_sub_mod/index.html'
27+
// There should be only only item with `cfg` note.
28+
//@ count - '//*[@class="stab portability"]' 1
29+
// And obviously the item should be "blabla".
30+
//@ has - '//dt' 'blablaNon-pistache'
31+
#[cfg(not(feature = "pistache"))]
32+
pub fn blabla() {}
33+
34+
pub use self::blabla as another;
35+
}

0 commit comments

Comments
 (0)