From 5f0043ace66f0db0581bc4bc52d90773cc23d3ac Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 31 May 2024 15:39:10 +0200 Subject: [PATCH 1/2] Handle no values cfg with --print=check-cfg --- compiler/rustc_driver_impl/src/lib.rs | 18 +++++++++++------- .../src/compiler-flags/print-check-cfg.md | 1 + tests/run-make/print-check-cfg/rmake.rs | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 08b97b4953e97..627fd74c8d77c 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -814,13 +814,17 @@ fn print_crate_info( match expected_values { ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")), ExpectedValues::Some(values) => { - check_cfgs.extend(values.iter().map(|value| { - if let Some(value) = value { - format!("{name}=\"{value}\"") - } else { - name.to_string() - } - })) + if !values.is_empty() { + check_cfgs.extend(values.iter().map(|value| { + if let Some(value) = value { + format!("{name}=\"{value}\"") + } else { + name.to_string() + } + })) + } else { + check_cfgs.push(format!("{name}=")) + } } } } diff --git a/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md b/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md index e55165b537404..a9237a0f4ef75 100644 --- a/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md +++ b/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md @@ -15,6 +15,7 @@ This print option works similarly to `--print=cfg` (modulo check-cfg specifics): - `cfg(feature, values("foo", "bar"))`: `feature="foo"` and `feature="bar"` - `cfg(feature, values(none(), ""))`: `feature` and `feature=""` - `cfg(feature, values(any()))`: `feature=any()` + - `cfg(feature, values())`: `feature=` - `cfg(any())`: `any()` - *nothing*: `any()=any()` diff --git a/tests/run-make/print-check-cfg/rmake.rs b/tests/run-make/print-check-cfg/rmake.rs index 2d52216442653..a0aa95c8abcf6 100644 --- a/tests/run-make/print-check-cfg/rmake.rs +++ b/tests/run-make/print-check-cfg/rmake.rs @@ -48,6 +48,20 @@ fn main() { doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="], }, }); + check(CheckCfg { + args: &["--check-cfg=cfg(feature, values())"], + contains: Contains::Some { + contains: &["feature="], + doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature"], + }, + }); + check(CheckCfg { + args: &["--check-cfg=cfg(feature, values())", "--check-cfg=cfg(feature, values(none()))"], + contains: Contains::Some { + contains: &["feature"], + doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="], + }, + }); check(CheckCfg { args: &[ r#"--check-cfg=cfg(feature, values(any()))"#, From f58bf91aceb7bc029bd130a84cbb156f9149491d Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 31 May 2024 15:42:07 +0200 Subject: [PATCH 2/2] Add missing tracking issue number for --print=check-cfg --- src/doc/unstable-book/src/compiler-flags/print-check-cfg.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md b/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md index a9237a0f4ef75..ab63c986e856e 100644 --- a/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md +++ b/src/doc/unstable-book/src/compiler-flags/print-check-cfg.md @@ -1,6 +1,6 @@ # `print=check-cfg` -The tracking issue for this feature is: [#XXXXXX](https://github.com/rust-lang/rust/issues/XXXXXX). +The tracking issue for this feature is: [#125704](https://github.com/rust-lang/rust/issues/125704). ------------------------