Skip to content

Commit f388b0f

Browse files
Rollup merge of rust-lang#89596 - GuillaumeGomez:implicit-doc-cfg, r=jyn514
Make cfg imply doc(cfg) This is a reopening of rust-lang#79341, rebased and modified a bit (we made a lot of refactoring in rustdoc's types so they needed to be reflected in this PR as well): * `hidden_cfg` is now in the `Cache` instead of `DocContext` because `cfg` information isn't stored anymore on `clean::Attributes` type but instead computed on-demand, so we need this information in later parts of rustdoc. * I removed the `bool_to_options` feature (which makes the code a bit simpler to read for `SingleExt` trait implementation. * I updated the version for the feature. There is only one thing I couldn't figure out: [this comment](rust-lang#79341 (comment)) > I think I'll likely scrap the whole `SingleExt` extension trait as the diagnostics for 0 and >1 items should be different. How/why should they differ? EDIT: this part has been solved, the current code was fine, just needed a little simplification. cc `@Nemo157` r? `@jyn514` Original PR description: This is only active when the `doc_cfg` feature is active. The implicit cfg can be overridden via `#[doc(cfg(...))]`, so e.g. to hide a `#[cfg]` you can use something like: ```rust #[cfg(unix)] #[doc(cfg(all()))] pub struct Unix; ``` By adding `#![doc(cfg_hide(foobar))]` to the crate attributes the cfg `#[cfg(foobar)]` (and _only_ that _exact_ cfg) will not be implicitly treated as a `doc(cfg)` to render a message in the documentation.
2 parents f6ba877 + a7586fd commit f388b0f

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

alloc/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
6868
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
6969
)]
70+
#![cfg_attr(
71+
not(bootstrap),
72+
doc(cfg_hide(not(test), not(any(test, bootstrap)), target_has_atomic = "ptr"))
73+
)]
7074
#![no_std]
7175
#![needs_allocator]
7276
#![warn(deprecated_in_future)]
@@ -146,6 +150,8 @@
146150
#![feature(associated_type_bounds)]
147151
#![feature(slice_group_by)]
148152
#![feature(decl_macro)]
153+
#![feature(doc_cfg)]
154+
#![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
149155
// Allow testing this library
150156

151157
#[cfg(test)]

core/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@
6060
test(no_crate_inject, attr(deny(warnings))),
6161
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
6262
)]
63+
#![cfg_attr(
64+
not(bootstrap),
65+
doc(cfg_hide(
66+
not(test),
67+
target_pointer_width = "16",
68+
target_pointer_width = "32",
69+
target_pointer_width = "64",
70+
target_has_atomic = "8",
71+
target_has_atomic = "16",
72+
target_has_atomic = "32",
73+
target_has_atomic = "64",
74+
target_has_atomic = "ptr",
75+
target_has_atomic_equal_alignment = "8",
76+
target_has_atomic_equal_alignment = "16",
77+
target_has_atomic_equal_alignment = "32",
78+
target_has_atomic_equal_alignment = "64",
79+
target_has_atomic_equal_alignment = "ptr",
80+
target_has_atomic_load_store = "8",
81+
target_has_atomic_load_store = "16",
82+
target_has_atomic_load_store = "32",
83+
target_has_atomic_load_store = "64",
84+
target_has_atomic_load_store = "ptr",
85+
))
86+
)]
6387
#![no_core]
6488
//
6589
// Lints:
@@ -133,6 +157,7 @@
133157
#![feature(doc_notable_trait)]
134158
#![feature(doc_primitive)]
135159
#![feature(exhaustive_patterns)]
160+
#![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
136161
#![feature(extern_types)]
137162
#![feature(fundamental)]
138163
#![feature(if_let_guard)]

std/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
test(no_crate_inject, attr(deny(warnings))),
196196
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
197197
)]
198+
#![cfg_attr(not(bootstrap), doc(cfg_hide(not(test), not(any(test, bootstrap)))))]
198199
// Don't link to std. We are std.
199200
#![no_std]
200201
#![warn(deprecated_in_future)]
@@ -263,6 +264,7 @@
263264
#![feature(custom_test_frameworks)]
264265
#![feature(decl_macro)]
265266
#![feature(doc_cfg)]
267+
#![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
266268
#![feature(doc_keyword)]
267269
#![feature(doc_masked)]
268270
#![feature(doc_notable_trait)]

std/src/os/raw/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ macro_rules! type_alias {
4646
}
4747

4848
type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8;
49+
#[doc(cfg(all()))]
4950
#[cfg(any(
5051
all(
5152
target_os = "linux",
@@ -88,6 +89,7 @@ type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8;
8889
all(target_os = "fuchsia", target_arch = "aarch64")
8990
))]}
9091
type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8;
92+
#[doc(cfg(all()))]
9193
#[cfg(not(any(
9294
all(
9395
target_os = "linux",
@@ -136,12 +138,16 @@ type_alias! { "ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; }
136138
type_alias! { "int.md", c_int = i32, NonZero_c_int = NonZeroI32; }
137139
type_alias! { "uint.md", c_uint = u32, NonZero_c_uint = NonZeroU32; }
138140
type_alias! { "long.md", c_long = i32, NonZero_c_long = NonZeroI32;
141+
#[doc(cfg(all()))]
139142
#[cfg(any(target_pointer_width = "32", windows))] }
140143
type_alias! { "ulong.md", c_ulong = u32, NonZero_c_ulong = NonZeroU32;
144+
#[doc(cfg(all()))]
141145
#[cfg(any(target_pointer_width = "32", windows))] }
142146
type_alias! { "long.md", c_long = i64, NonZero_c_long = NonZeroI64;
147+
#[doc(cfg(all()))]
143148
#[cfg(all(target_pointer_width = "64", not(windows)))] }
144149
type_alias! { "ulong.md", c_ulong = u64, NonZero_c_ulong = NonZeroU64;
150+
#[doc(cfg(all()))]
145151
#[cfg(all(target_pointer_width = "64", not(windows)))] }
146152
type_alias! { "longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; }
147153
type_alias! { "ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; }

std/src/os/windows/raw.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use crate::os::raw::c_void;
77
#[stable(feature = "raw_ext", since = "1.1.0")]
88
pub type HANDLE = *mut c_void;
99
#[cfg(target_pointer_width = "32")]
10+
#[doc(cfg(all()))]
1011
#[stable(feature = "raw_ext", since = "1.1.0")]
1112
pub type SOCKET = u32;
1213
#[cfg(target_pointer_width = "64")]
14+
#[doc(cfg(all()))]
1315
#[stable(feature = "raw_ext", since = "1.1.0")]
1416
pub type SOCKET = u64;

0 commit comments

Comments
 (0)