Skip to content

Commit 0e2cd33

Browse files
committed
Cleanup std::os
1 parent c825bc4 commit 0e2cd33

File tree

5 files changed

+113
-111
lines changed

5 files changed

+113
-111
lines changed

library/std/src/os/linux/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Linux-specific definitions.
22
33
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![doc(cfg(target_os = "linux"))]
45

56
pub mod fs;
67
pub mod raw;

library/std/src/os/linux/raw.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
definitions"
1010
)]
1111
#![allow(deprecated)]
12-
#![allow(missing_debug_implementations)]
1312

1413
use crate::os::raw::c_ulong;
1514

library/std/src/os/mod.rs

Lines changed: 89 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,93 @@
33
#![stable(feature = "os", since = "1.0.0")]
44
#![allow(missing_docs, nonstandard_style, missing_debug_implementations)]
55

6-
// When documenting libstd we want to show unix/windows/linux/wasi modules as these are the "main
7-
// modules" that are used across platforms, so all modules are enabled when `cfg(doc)` is set.
8-
// This should help show platform-specific functionality in a hopefully cross-platform way in the
9-
// documentation.
10-
// Note that we deliberately avoid `cfg_if!` here to work around a rust-analyzer bug that would make
11-
// `std::os` submodules unusable: https://github.com/rust-analyzer/rust-analyzer/issues/6038
12-
13-
#[cfg(doc)]
14-
#[stable(feature = "rust1", since = "1.0.0")]
15-
pub use crate::sys::unix_ext as unix;
16-
17-
#[cfg(doc)]
18-
#[stable(feature = "rust1", since = "1.0.0")]
19-
pub use crate::sys::windows_ext as windows;
20-
21-
#[cfg(doc)]
22-
#[doc(cfg(target_os = "linux"))]
23-
pub mod linux;
24-
25-
#[cfg(doc)]
26-
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
27-
pub use crate::sys::wasi_ext as wasi;
28-
29-
// If we're not documenting libstd then we just expose the main modules as we otherwise would.
30-
31-
#[cfg(not(doc))]
32-
#[cfg(any(unix, target_os = "hermit"))]
33-
#[stable(feature = "rust1", since = "1.0.0")]
34-
pub use crate::sys::ext as unix;
35-
36-
#[cfg(not(doc))]
37-
#[cfg(windows)]
38-
#[stable(feature = "rust1", since = "1.0.0")]
39-
pub use crate::sys::ext as windows;
40-
41-
#[cfg(not(doc))]
42-
#[cfg(any(target_os = "linux", target_os = "l4re"))]
43-
pub mod linux;
44-
45-
#[cfg(not(doc))]
46-
#[cfg(target_os = "wasi")]
47-
pub mod wasi;
48-
49-
#[cfg(target_os = "android")]
50-
pub mod android;
51-
#[cfg(target_os = "dragonfly")]
52-
pub mod dragonfly;
53-
#[cfg(target_os = "emscripten")]
54-
pub mod emscripten;
55-
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
56-
pub mod fortanix_sgx;
57-
#[cfg(target_os = "freebsd")]
58-
pub mod freebsd;
59-
#[cfg(target_os = "fuchsia")]
60-
pub mod fuchsia;
61-
#[cfg(target_os = "haiku")]
62-
pub mod haiku;
63-
#[cfg(target_os = "illumos")]
64-
pub mod illumos;
65-
#[cfg(target_os = "ios")]
66-
pub mod ios;
67-
#[cfg(target_os = "macos")]
68-
pub mod macos;
69-
#[cfg(target_os = "netbsd")]
70-
pub mod netbsd;
71-
#[cfg(target_os = "openbsd")]
72-
pub mod openbsd;
73-
#[cfg(target_os = "redox")]
74-
pub mod redox;
75-
#[cfg(target_os = "solaris")]
76-
pub mod solaris;
77-
#[cfg(target_os = "vxworks")]
78-
pub mod vxworks;
79-
806
pub mod raw;
7+
8+
cfg_if::cfg_if! {
9+
if #[cfg(all(doc, not(any(target_os = "hermit",
10+
all(target_arch = "wasm32", not(target_os = "wasi")),
11+
all(target_vendor = "fortanix", target_env = "sgx")))))]{
12+
// When documenting std we want to show the `unix`, `windows`, `linux` and `wasi`
13+
// modules as these are the "main modules" that are used across platforms,
14+
// so these modules are enabled when `cfg(doc)` is set.
15+
// This should help show platform-specific functionality in a hopefully cross-platform
16+
// way in the documentation.
17+
18+
#[stable(feature = "rust1", since = "1.0.0")]
19+
pub use crate::sys::unix_ext as unix;
20+
21+
pub mod linux;
22+
23+
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
24+
pub use crate::sys::wasi_ext as wasi;
25+
26+
#[stable(feature = "rust1", since = "1.0.0")]
27+
pub use crate::sys::windows_ext as windows;
28+
} else if #[cfg(doc)] {
29+
// On certain platforms right now the "main modules" modules that are
30+
// documented don't compile (missing things in `libc` which is empty),
31+
// so just omit them with an empty module.
32+
33+
#[unstable(issue = "none", feature = "std_internals")]
34+
pub mod unix {}
35+
36+
#[unstable(issue = "none", feature = "std_internals")]
37+
pub mod linux {}
38+
39+
#[unstable(issue = "none", feature = "std_internals")]
40+
pub mod wasi {}
41+
42+
#[unstable(issue = "none", feature = "std_internals")]
43+
pub mod windows {}
44+
} else {
45+
// If we're not documenting std then we only expose modules appropriate for the
46+
// current platform.
47+
48+
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
49+
pub mod fortanix_sgx;
50+
51+
#[cfg(any(unix, target_os = "hermit"))]
52+
#[stable(feature = "rust1", since = "1.0.0")]
53+
pub use crate::sys::ext as unix;
54+
#[cfg(target_os = "android")]
55+
pub mod android;
56+
#[cfg(target_os = "dragonfly")]
57+
pub mod dragonfly;
58+
#[cfg(target_os = "emscripten")]
59+
pub mod emscripten;
60+
#[cfg(target_os = "freebsd")]
61+
pub mod freebsd;
62+
#[cfg(target_os = "fuchsia")]
63+
pub mod fuchsia;
64+
#[cfg(target_os = "haiku")]
65+
pub mod haiku;
66+
#[cfg(target_os = "illumos")]
67+
pub mod illumos;
68+
#[cfg(target_os = "ios")]
69+
pub mod ios;
70+
#[cfg(target_os = "l4re")]
71+
pub mod linux;
72+
#[cfg(target_os = "linux")]
73+
pub mod linux;
74+
#[cfg(target_os = "macos")]
75+
pub mod macos;
76+
#[cfg(target_os = "netbsd")]
77+
pub mod netbsd;
78+
#[cfg(target_os = "openbsd")]
79+
pub mod openbsd;
80+
#[cfg(target_os = "redox")]
81+
pub mod redox;
82+
#[cfg(target_os = "solaris")]
83+
pub mod solaris;
84+
85+
#[cfg(target_os = "vxworks")]
86+
pub mod vxworks;
87+
88+
#[cfg(target_os = "wasi")]
89+
pub mod wasi;
90+
91+
#[cfg(windows)]
92+
#[stable(feature = "rust1", since = "1.0.0")]
93+
pub use crate::sys::ext as windows;
94+
}
95+
}

library/std/src/os/redox/raw.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
definitions"
1010
)]
1111
#![allow(deprecated)]
12-
#![allow(missing_debug_implementations)]
1312

1413
use crate::os::raw::{c_char, c_int, c_long, c_ulong, c_void};
1514

library/std/src/sys/mod.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,49 +49,43 @@ cfg_if::cfg_if! {
4949
}
5050
}
5151

52-
// Import essential modules from both platforms when documenting. These are
53-
// then later used in the `std::os` module when documenting, for example,
54-
// Windows when we're compiling for Linux.
52+
// Import essential modules from platforms used in `std::os` when documenting.
53+
//
54+
// Note that on some platforms those modules don't compile
55+
// (missing things in `libc` which is empty), so they are not included in `std::os` and can be
56+
// omitted here as well.
5557

5658
#[cfg(doc)]
59+
#[cfg(not(any(
60+
target_os = "hermit",
61+
all(target_arch = "wasm32", not(target_os = "wasi")),
62+
all(target_vendor = "fortanix", target_env = "sgx")
63+
)))]
5764
cfg_if::cfg_if! {
5865
if #[cfg(unix)] {
59-
// On unix we'll document what's already available
6066
#[stable(feature = "rust1", since = "1.0.0")]
6167
pub use self::ext as unix_ext;
62-
} else if #[cfg(any(target_os = "hermit",
63-
all(target_arch = "wasm32", not(target_os = "wasi")),
64-
all(target_vendor = "fortanix", target_env = "sgx")))] {
65-
// On non-WASI wasm right now the module below doesn't compile
66-
// (missing things in `libc` which is empty) so just omit everything
67-
// with an empty module
68-
#[unstable(issue = "none", feature = "std_internals")]
69-
#[allow(missing_docs)]
70-
pub mod unix_ext {}
7168
} else {
7269
#[path = "unix/ext/mod.rs"]
7370
pub mod unix_ext;
7471
}
7572
}
7673

7774
#[cfg(doc)]
75+
#[cfg(not(any(
76+
target_os = "hermit",
77+
all(target_arch = "wasm32", not(target_os = "wasi")),
78+
all(target_vendor = "fortanix", target_env = "sgx")
79+
)))]
7880
cfg_if::cfg_if! {
7981
if #[cfg(windows)] {
80-
// On windows we'll just be documenting what's already available
8182
#[allow(missing_docs)]
8283
#[stable(feature = "rust1", since = "1.0.0")]
8384
pub use self::ext as windows_ext;
84-
} else if #[cfg(any(target_os = "hermit",
85-
all(target_arch = "wasm32", not(target_os = "wasi")),
86-
all(target_vendor = "fortanix", target_env = "sgx")))] {
87-
// On non-WASI wasm right now the shim below doesn't compile, so
88-
// just omit it
89-
#[unstable(issue = "none", feature = "std_internals")]
90-
#[allow(missing_docs)]
91-
pub mod windows_ext {}
9285
} else {
93-
// On all other platforms (aka linux/osx/etc) then pull in a "minimal"
86+
// On non-Windows platforms (aka linux/osx/etc) pull in a "minimal"
9487
// amount of windows goop which ends up compiling
88+
9589
#[macro_use]
9690
#[path = "windows/compat.rs"]
9791
mod compat;
@@ -105,22 +99,16 @@ cfg_if::cfg_if! {
10599
}
106100

107101
#[cfg(doc)]
102+
#[cfg(not(any(
103+
target_os = "hermit",
104+
all(target_arch = "wasm32", not(target_os = "wasi")),
105+
all(target_vendor = "fortanix", target_env = "sgx")
106+
)))]
108107
cfg_if::cfg_if! {
109108
if #[cfg(target_os = "wasi")] {
110-
// On WASI we'll document what's already available
111109
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
112110
pub use self::ext as wasi_ext;
113-
} else if #[cfg(any(target_os = "hermit",
114-
target_arch = "wasm32",
115-
all(target_vendor = "fortanix", target_env = "sgx")))] {
116-
// On non-WASI wasm right now the module below doesn't compile
117-
// (missing things in `libc` which is empty) so just omit everything
118-
// with an empty module
119-
#[unstable(issue = "none", feature = "std_internals")]
120-
#[allow(missing_docs)]
121-
pub mod wasi_ext {}
122-
} else {
123-
// On other platforms like Windows document the bare bones of WASI
111+
} else {
124112
#[path = "wasi/ext/mod.rs"]
125113
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
126114
pub mod wasi_ext;

0 commit comments

Comments
 (0)