Skip to content

Commit 2a264b1

Browse files
Rollup merge of rust-lang#158252 - hkBst:std-os-cfg-select, r=jhpratt
Use `cfg_select` in `std::os` rust-lang#81969 replaced `cgf_if` with bare `cfg`, but since `cfg_select` is now built in, it shouldn't pose a problem to rust-analyzer any more, so we should be able to go back to better code.
2 parents 50a5f64 + 24d4439 commit 2a264b1

1 file changed

Lines changed: 66 additions & 117 deletions

File tree

library/std/src/os/mod.rs

Lines changed: 66 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,121 +6,83 @@
66

77
pub mod raw;
88

9-
// The code below could be written clearer using `cfg_if!`. However, the items below are
10-
// publicly exported by `std` and external tools can have trouble analysing them because of the use
11-
// of a macro that is not vendored by Rust and included in the toolchain.
12-
// See https://github.com/rust-analyzer/rust-analyzer/issues/6038.
9+
// # Important platforms
1310

14-
// On certain platforms right now the "main modules" modules that are
15-
// documented don't compile (missing things in `libc` which is empty),
16-
// so just omit them with an empty module and add the "unstable" attribute.
17-
18-
// darwin, unix, linux, wasi and windows are handled a bit differently.
19-
#[cfg(all(
20-
doc,
21-
any(
22-
all(target_arch = "wasm32", not(target_os = "wasi")),
23-
all(target_vendor = "fortanix", target_env = "sgx")
24-
)
25-
))]
26-
#[unstable(issue = "none", feature = "std_internals")]
27-
pub mod darwin {}
28-
#[cfg(all(
29-
doc,
30-
any(
31-
all(target_arch = "wasm32", not(target_os = "wasi")),
32-
all(target_vendor = "fortanix", target_env = "sgx")
33-
)
34-
))]
35-
#[unstable(issue = "none", feature = "std_internals")]
36-
pub mod unix {}
37-
#[cfg(all(
38-
doc,
39-
any(
40-
all(target_arch = "wasm32", not(target_os = "wasi")),
41-
all(target_vendor = "fortanix", target_env = "sgx")
42-
)
43-
))]
44-
#[unstable(issue = "none", feature = "std_internals")]
45-
pub mod linux {}
46-
#[cfg(all(
47-
doc,
48-
any(
49-
all(target_arch = "wasm32", not(target_os = "wasi")),
50-
all(target_vendor = "fortanix", target_env = "sgx")
51-
)
52-
))]
53-
#[unstable(issue = "none", feature = "std_internals")]
54-
pub mod wasi {}
55-
#[cfg(all(
56-
doc,
11+
// We always want to show documentation for the most important platforms,
12+
// so these are handled specially here.
13+
//
14+
// FIXME: On certain platforms compilation errors (due to empty `libc`),
15+
// prevent this, so we substitute an unstable empty module.
16+
#[cfg(doc)]
17+
cfg_select! {
5718
any(
5819
all(target_arch = "wasm32", not(target_os = "wasi")),
5920
all(target_vendor = "fortanix", target_env = "sgx")
60-
)
61-
))]
62-
#[unstable(issue = "none", feature = "std_internals")]
63-
pub mod windows {}
21+
) => {
22+
#[unstable(issue = "none", feature = "std_internals")]
23+
pub mod darwin {}
6424

65-
// darwin
66-
#[cfg(not(all(
67-
doc,
68-
any(
69-
all(target_arch = "wasm32", not(target_os = "wasi")),
70-
all(target_vendor = "fortanix", target_env = "sgx")
71-
)
72-
)))]
73-
#[cfg(any(target_vendor = "apple", doc))]
74-
pub mod darwin;
25+
#[unstable(issue = "none", feature = "std_internals")]
26+
pub mod unix {}
7527

76-
// unix
77-
#[cfg(not(all(
78-
doc,
79-
any(
80-
all(target_arch = "wasm32", not(target_os = "wasi")),
81-
all(target_vendor = "fortanix", target_env = "sgx")
82-
)
83-
)))]
84-
#[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
85-
pub mod unix;
28+
#[unstable(issue = "none", feature = "std_internals")]
29+
pub mod linux {}
8630

87-
// linux
88-
#[cfg(not(all(
89-
doc,
90-
any(
91-
all(target_arch = "wasm32", not(target_os = "wasi")),
92-
all(target_vendor = "fortanix", target_env = "sgx")
93-
)
94-
)))]
95-
#[cfg(any(target_os = "linux", doc))]
96-
pub mod linux;
31+
#[unstable(issue = "none", feature = "std_internals")]
32+
pub mod wasi {}
9733

98-
// wasi
99-
#[cfg(not(all(
100-
doc,
101-
any(
102-
all(target_arch = "wasm32", not(target_os = "wasi")),
103-
all(target_vendor = "fortanix", target_env = "sgx")
104-
)
105-
)))]
106-
#[cfg(any(target_os = "wasi", any(target_env = "p1", target_env = "p2"), doc))]
107-
pub mod wasi;
34+
#[unstable(issue = "none", feature = "std_internals")]
35+
pub mod windows {}
36+
}
37+
_ => {
38+
// important platforms
39+
pub mod darwin;
40+
pub mod linux;
41+
pub mod unix;
42+
pub mod wasi;
43+
pub mod wasip2;
44+
pub mod windows;
45+
}
46+
}
47+
#[cfg(not(doc))] // to prevent double module declarations
48+
cfg_select! {
49+
target_family = "unix" => {
50+
pub mod unix;
51+
#[cfg(target_vendor = "apple")]
52+
pub mod darwin;
53+
#[cfg(target_os = "linux")]
54+
pub mod linux;
55+
}
56+
target_family = "wasm" => {
57+
#[cfg(any(target_env = "p1", target_env = "p2"))]
58+
pub mod wasi;
59+
#[cfg(target_env = "p2")]
60+
pub mod wasip2;
61+
}
62+
target_family = "windows" => {
63+
pub mod windows;
64+
}
65+
_ => { /* handled below */ }
66+
}
10867

109-
#[cfg(any(all(target_os = "wasi", target_env = "p2"), doc))]
110-
pub mod wasip2;
68+
// # Special modules
11169

112-
// windows
113-
#[cfg(not(all(
114-
doc,
115-
any(
116-
all(target_arch = "wasm32", not(target_os = "wasi")),
117-
all(target_vendor = "fortanix", target_env = "sgx")
118-
)
119-
)))]
120-
#[cfg(any(windows, doc))]
121-
pub mod windows;
70+
#[cfg(any(
71+
unix,
72+
target_os = "hermit",
73+
target_os = "trusty",
74+
target_os = "wasi",
75+
target_os = "motor",
76+
doc
77+
))]
78+
pub mod fd;
79+
80+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
81+
mod net;
82+
83+
// # Ordinary platforms
84+
// `cfg(doc)` not handled specially
12285

123-
// Others.
12486
#[cfg(target_os = "aix")]
12587
pub mod aix;
12688
#[cfg(target_os = "android")]
@@ -183,16 +145,3 @@ pub mod vita;
183145
pub mod vxworks;
184146
#[cfg(target_os = "xous")]
185147
pub mod xous;
186-
187-
#[cfg(any(
188-
unix,
189-
target_os = "hermit",
190-
target_os = "trusty",
191-
target_os = "wasi",
192-
target_os = "motor",
193-
doc
194-
))]
195-
pub mod fd;
196-
197-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
198-
mod net;

0 commit comments

Comments
 (0)