Skip to content

Commit a8a71d0

Browse files
Rollup merge of #125452 - Urgau:check-cfg-libraries-cleanup, r=bjorn3
Cleanup check-cfg handling in core and std Follow-up to #125296 where we: - expect any feature cfg in std, due to `#[path]` imports - move some check-cfg args inside the `build.rs` as per Cargo recommendation - and replace the fake Cargo feature `"restricted-std"` by the custom cfg `restricted_std` Fixes #125296 (comment) r? `@bjorn3` (maybe, feel free to re-roll)
2 parents 0de052a + 45ad60d commit a8a71d0

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

library/core/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ check-cfg = [
4646
'cfg(bootstrap)',
4747
'cfg(no_fp_fmt_parse)',
4848
'cfg(stdarch_intel_sde)',
49-
# This matches `EXTRA_CHECK_CFGS` in `src/bootstrap/src/lib.rs`.
49+
# core use #[path] imports to portable-simd `core_simd` crate
50+
# and to stdarch `core_arch` crate which messes-up with Cargo list
51+
# of declared features, we therefor expect any feature cfg
5052
'cfg(feature, values(any()))',
5153
]

library/std/Cargo.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ test = true
100100

101101
[lints.rust.unexpected_cfgs]
102102
level = "warn"
103+
# x.py uses beta cargo, so `check-cfg` entries do not yet take effect
104+
# for rust-lang/rust. But for users of `-Zbuild-std` it does.
105+
# The unused warning is waiting for rust-lang/cargo#13925 to reach beta.
103106
check-cfg = [
104107
'cfg(bootstrap)',
105-
'cfg(backtrace_in_libstd)',
106-
'cfg(netbsd10)',
107108
'cfg(target_arch, values("xtensa"))',
108-
'cfg(feature, values("std", "as_crate"))',
109+
# std use #[path] imports to portable-simd `std_float` crate
110+
# and to the `backtrace` crate which messes-up with Cargo list
111+
# of declared features, we therefor expect any feature cfg
112+
'cfg(feature, values(any()))',
109113
]

library/std/build.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10+
11+
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1012
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
1113
println!("cargo:rustc-cfg=netbsd10");
1214
}
15+
16+
println!("cargo:rustc-check-cfg=cfg(restricted_std)");
1317
if target_os == "linux"
1418
|| target_os == "android"
1519
|| target_os == "netbsd"
@@ -59,8 +63,11 @@ fn main() {
5963
// - arch=avr
6064
// - JSON targets
6165
// - Any new targets that have not been explicitly added above.
62-
println!("cargo:rustc-cfg=feature=\"restricted-std\"");
66+
println!("cargo:rustc-cfg=restricted_std");
6367
}
64-
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
68+
69+
println!("cargo:rustc-check-cfg=cfg(backtrace_in_libstd)");
6570
println!("cargo:rustc-cfg=backtrace_in_libstd");
71+
72+
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
6673
}

library/std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@
213213
//! [array]: prim@array
214214
//! [slice]: prim@slice
215215
216-
#![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))]
216+
#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
217217
#![cfg_attr(
218-
feature = "restricted-std",
218+
restricted_std,
219219
unstable(
220220
feature = "restricted_std",
221221
issue = "none",

src/bootstrap/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
9292
(Some(Mode::Std), "no_global_oom_handling", None),
9393
(Some(Mode::Std), "no_rc", None),
9494
(Some(Mode::Std), "no_sync", None),
95-
(Some(Mode::Std), "netbsd10", None),
96-
(Some(Mode::Std), "backtrace_in_libstd", None),
9795
/* Extra values not defined in the built-in targets yet, but used in std */
9896
(Some(Mode::Std), "target_env", Some(&["libnx", "p2"])),
9997
(Some(Mode::Std), "target_os", Some(&["visionos"])),

0 commit comments

Comments
 (0)