Skip to content

Commit 90bd404

Browse files
committed
simplify check_cfg_arg impl
1 parent 9725c4b commit 90bd404

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

compiler/rustc_session/src/config/cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//!
1010
//! ## Adding a new cfg
1111
//!
12-
//! Adding a new feature requires two new symbols one for the cfg itself
13-
//! and the second one for the unstable feature gate, those are defined in
12+
//! Adding a new feature requires two new symbols: one for the cfg itself
13+
//! and the second one for the unstable feature gate; those are defined in
1414
//! `rustc_span::symbol`.
1515
//!
1616
//! As well as the following points,
@@ -107,8 +107,8 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
107107
//
108108
// The tests are in tests/ui/cfg/disallowed-cli-cfgs.rs.
109109

110-
// By-default all builtin cfgs are disallowed, only those are allowed:
111-
// - test: as it makes sense to the have the `test` cfg active without the builtin
110+
// By default all builtin cfgs are disallowed, but these are allowed:
111+
// - test: as it makes sense to have the `test` cfg active without the builtin
112112
// test harness. See Cargo `harness = false` config.
113113
//
114114
// Cargo `--cfg test`: https://github.com/rust-lang/cargo/blob/bc89bffa5987d4af8f71011c7557119b39e44a65/src/cargo/core/compiler/mod.rs#L1124

src/bootstrap/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ const LLD_FILE_NAMES: &[&str] = &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"];
8282
/// Extra `--check-cfg` to add when building the compiler or tools
8383
/// (Mode restriction, config name, config values (if any))
8484
#[expect(clippy::type_complexity)] // It's fine for hard-coded list and type is explained above.
85-
const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
86-
(Some(Mode::Rustc), "bootstrap", None),
87-
(Some(Mode::Codegen), "bootstrap", None),
88-
(Some(Mode::ToolRustcPrivate), "bootstrap", None),
89-
(Some(Mode::ToolStd), "bootstrap", None),
90-
(Some(Mode::ToolRustcPrivate), "rust_analyzer", None),
91-
(Some(Mode::ToolStd), "rust_analyzer", None),
85+
const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, &[&'static str])] = &[
86+
(Some(Mode::Rustc), "bootstrap", &[]),
87+
(Some(Mode::Codegen), "bootstrap", &[]),
88+
(Some(Mode::ToolRustcPrivate), "bootstrap", &[]),
89+
(Some(Mode::ToolStd), "bootstrap", &[]),
90+
(Some(Mode::ToolRustcPrivate), "rust_analyzer", &[]),
91+
(Some(Mode::ToolStd), "rust_analyzer", &[]),
9292
// Any library specific cfgs like `target_os`, `target_arch` should be put in
9393
// priority the `[lints.rust.unexpected_cfgs.check-cfg]` table
9494
// in the appropriate `library/{std,alloc,core}/Cargo.toml`

src/bootstrap/src/utils/helpers.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,13 @@ where
490490
})
491491
}
492492

493-
/// Create a `--check-cfg` argument invocation for a given name
494-
/// and it's values.
495-
pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
496-
// Creating a string of the values by concatenating each value:
497-
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
498-
let next = match values {
499-
Some(values) => {
500-
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
501-
502-
tmp.insert_str(1, "values(");
503-
tmp.push(')');
504-
tmp
505-
}
506-
None => "".to_string(),
507-
};
508-
format!("--check-cfg=cfg({name}{next})")
493+
/// Create a `--check-cfg` argument invocation for a given name and values.
494+
pub fn check_cfg_arg(name: &str, values: &[&str]) -> String {
495+
if values.is_empty() {
496+
format!("--check-cfg=cfg({name})")
497+
} else {
498+
format!("--check-cfg=cfg({name},values(\"{}\"))", values.join("\",\""))
499+
}
509500
}
510501

511502
/// Prepares `BootstrapCommand` that runs git inside the source directory if given.

0 commit comments

Comments
 (0)