about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-06-04 08:25:48 +0100
committerGitHub <noreply@github.com>2024-06-04 08:25:48 +0100
commit756af9d5bcb073ba8344d2504614922a4bab22e4 (patch)
treeea7597a168a815a26d75fd8630d0afdbb4e9a473
parentb477f890417fedbb4178b1f7385e939cb6eac32f (diff)
parentf58bf91aceb7bc029bd130a84cbb156f9149491d (diff)
downloadrust-756af9d5bcb073ba8344d2504614922a4bab22e4.tar.gz
rust-756af9d5bcb073ba8344d2504614922a4bab22e4.zip
Rollup merge of #125818 - Urgau:print-check-cfg-no-values, r=petrochenkov
Handle no values cfgs with `--print=check-cfg`

This PR fix a bug with `--print=check-cfg`, where no values cfgs where not printed since we only printed cfgs that had at least one values.

The representation I choose is `CFG=`, since it doesn't correspond to any valid config, it also IMO nicely complements the `values()` (to indicate no values). Representing the absence of value by the absence of the value.

So for `cfg(feature, values())` we would print `feature=`.

I also added the missing tracking issue number in the doc.

r? ```@petrochenkov```
-rw-r--r--compiler/rustc_driver_impl/src/lib.rs18
-rw-r--r--src/doc/unstable-book/src/compiler-flags/print-check-cfg.md3
-rw-r--r--tests/run-make/print-check-cfg/rmake.rs14
3 files changed, 27 insertions, 8 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index 08b97b4953e..627fd74c8d7 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 e55165b5374..ab63c986e85 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).
 
 ------------------------
 
@@ -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 2d522164426..a0aa95c8abc 100644
--- a/tests/run-make/print-check-cfg/rmake.rs
+++ b/tests/run-make/print-check-cfg/rmake.rs
@@ -49,6 +49,20 @@ fn main() {
         },
     });
     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()))"#,
             r#"--check-cfg=cfg(feature, values("tmp"))"#,