From 85e476556b5c3622ef5356f31b724d2c2b5d2a1d Mon Sep 17 00:00:00 2001
From: Urgau <urgau@numericable.fr>
Date: Fri, 29 Nov 2024 18:04:36 +0100
Subject: [PATCH 1/3] Add specific test for check-cfg "and X more" diagnostic

---
 tests/ui/check-cfg/and-more-diagnostic.rs     | 13 +++++++++++++
 tests/ui/check-cfg/and-more-diagnostic.stderr | 12 ++++++++++++
 tests/ui/check-cfg/mix.rs                     |  2 --
 tests/ui/check-cfg/mix.stderr                 | 11 +----------
 4 files changed, 26 insertions(+), 12 deletions(-)
 create mode 100644 tests/ui/check-cfg/and-more-diagnostic.rs
 create mode 100644 tests/ui/check-cfg/and-more-diagnostic.stderr

diff --git a/tests/ui/check-cfg/and-more-diagnostic.rs b/tests/ui/check-cfg/and-more-diagnostic.rs
new file mode 100644
index 0000000000000..82867f3b43547
--- /dev/null
+++ b/tests/ui/check-cfg/and-more-diagnostic.rs
@@ -0,0 +1,13 @@
+// This test makes sure that we don't emit a long list of possible values
+// but that we stop at a fix point and say "and X more".
+//
+//@ check-pass
+//@ no-auto-check-cfg
+//@ compile-flags: --check-cfg=cfg()
+//@ normalize-stderr-test: "and \d+ more" -> "and X more"
+//@ normalize-stderr-test: "`[a-zA-Z0-9_-]+`" -> "`xxx`"
+
+fn main() {
+    cfg!(target_feature = "zebra");
+    //~^ WARNING unexpected `cfg` condition value
+}
diff --git a/tests/ui/check-cfg/and-more-diagnostic.stderr b/tests/ui/check-cfg/and-more-diagnostic.stderr
new file mode 100644
index 0000000000000..2ac80c84c37de
--- /dev/null
+++ b/tests/ui/check-cfg/and-more-diagnostic.stderr
@@ -0,0 +1,12 @@
+warning: unexpected `xxx` condition value: `xxx`
+  --> $DIR/and-more-diagnostic.rs:11:10
+   |
+LL |     cfg!(target_feature = "zebra");
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: expected values for `xxx` are: `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, `xxx`, and `xxx` and X more
+   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
+   = note: `#[warn(unexpected_cfgs)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/check-cfg/mix.rs b/tests/ui/check-cfg/mix.rs
index ac244f4fc09df..e9a2de2f67282 100644
--- a/tests/ui/check-cfg/mix.rs
+++ b/tests/ui/check-cfg/mix.rs
@@ -75,8 +75,6 @@ fn test_cfg_macro() {
     //~^ WARNING unexpected `cfg` condition value
     //~| WARNING unexpected `cfg` condition value
     //~| WARNING unexpected `cfg` condition value
-    cfg!(target_feature = "zebra");
-    //~^ WARNING unexpected `cfg` condition value
 }
 
 fn main() {}
diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr
index 32eb01c7018b0..231236799c69c 100644
--- a/tests/ui/check-cfg/mix.stderr
+++ b/tests/ui/check-cfg/mix.stderr
@@ -245,14 +245,5 @@ LL |     cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
    = help: to expect this configuration use `--check-cfg=cfg(feature, values("zebra"))`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
 
-warning: unexpected `cfg` condition value: `zebra`
-  --> $DIR/mix.rs:78:10
-   |
-LL |     cfg!(target_feature = "zebra");
-   |          ^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 252 more
-   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
-
-warning: 27 warnings emitted
+warning: 26 warnings emitted
 

From 1c4657d3cd1cef28dfd89d8f3a3e1970487d2ee0 Mon Sep 17 00:00:00 2001
From: Urgau <urgau@numericable.fr>
Date: Sun, 1 Dec 2024 18:18:19 +0100
Subject: [PATCH 2/3] compiletest: un-escape new-line in normalize replacement
 string

---
 src/tools/compiletest/src/header.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index fe4c5fdd8b51c..0a54f17725e2b 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -1135,6 +1135,8 @@ fn parse_normalize_rule(header: &str) -> Option<(String, String)> {
     .captures(header)?;
     let regex = captures["regex"].to_owned();
     let replacement = captures["replacement"].to_owned();
+    // FIXME: Support escaped new-line in strings.
+    let replacement = replacement.replace("\\n", "\n");
     Some((regex, replacement))
 }
 

From 43bed16b8bc4f410934d6cf983a8f3c84d66ac91 Mon Sep 17 00:00:00 2001
From: Urgau <urgau@numericable.fr>
Date: Sun, 1 Dec 2024 18:19:20 +0100
Subject: [PATCH 3/3] Reduce conflicts for check-cfg `target_feature` cfg
 values

---
 tests/ui/check-cfg/target_feature.rs        |  18 ++
 tests/ui/check-cfg/target_feature.stderr    | 297 ++++++++++++++++++++
 tests/ui/check-cfg/well-known-values.rs     |   4 +-
 tests/ui/check-cfg/well-known-values.stderr |  11 +-
 4 files changed, 318 insertions(+), 12 deletions(-)
 create mode 100644 tests/ui/check-cfg/target_feature.rs
 create mode 100644 tests/ui/check-cfg/target_feature.stderr

diff --git a/tests/ui/check-cfg/target_feature.rs b/tests/ui/check-cfg/target_feature.rs
new file mode 100644
index 0000000000000..6028dae66c4d4
--- /dev/null
+++ b/tests/ui/check-cfg/target_feature.rs
@@ -0,0 +1,18 @@
+// This test prints all the possible values for the `target_feature` cfg
+// as a way to assert the expected values and reflect on any changes made
+// to the `target_feature` cfg in the compiler.
+//
+// The output of this test  does not reflect the actual output seen by
+// users which will see a truncated list of possible values (at worst).
+//
+// In case of test output differences, just `--bless` the test.
+//
+//@ check-pass
+//@ no-auto-check-cfg
+//@ compile-flags: --check-cfg=cfg() -Zcheck-cfg-all-expected
+//@ normalize-stderr-test: "`, `" -> "`\n`"
+
+fn main() {
+    cfg!(target_feature = "_UNEXPECTED_VALUE");
+    //~^ WARNING unexpected `cfg` condition value
+}
diff --git a/tests/ui/check-cfg/target_feature.stderr b/tests/ui/check-cfg/target_feature.stderr
new file mode 100644
index 0000000000000..2674a97a551e4
--- /dev/null
+++ b/tests/ui/check-cfg/target_feature.stderr
@@ -0,0 +1,297 @@
+warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
+  --> $DIR/target_feature.rs:16:10
+   |
+LL |     cfg!(target_feature = "_UNEXPECTED_VALUE");
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: expected values for `target_feature` are: `10e60`
+`2e3`
+`3e3r1`
+`3e3r2`
+`3e3r3`
+`3e7`
+`7e10`
+`a`
+`aclass`
+`adx`
+`aes`
+`altivec`
+`alu32`
+`amx-bf16`
+`amx-complex`
+`amx-fp16`
+`amx-int8`
+`amx-tile`
+`atomics`
+`avx`
+`avx2`
+`avx512bf16`
+`avx512bitalg`
+`avx512bw`
+`avx512cd`
+`avx512dq`
+`avx512f`
+`avx512fp16`
+`avx512ifma`
+`avx512vbmi`
+`avx512vbmi2`
+`avx512vl`
+`avx512vnni`
+`avx512vp2intersect`
+`avx512vpopcntdq`
+`avxifma`
+`avxneconvert`
+`avxvnni`
+`avxvnniint16`
+`avxvnniint8`
+`backchain`
+`bf16`
+`bmi1`
+`bmi2`
+`bti`
+`bulk-memory`
+`c`
+`cache`
+`cmpxchg16b`
+`crc`
+`crt-static`
+`cssc`
+`d`
+`d32`
+`dit`
+`doloop`
+`dotprod`
+`dpb`
+`dpb2`
+`dsp`
+`dsp1e2`
+`dspe60`
+`e`
+`e1`
+`e2`
+`ecv`
+`edsp`
+`elrw`
+`ermsb`
+`exception-handling`
+`extended-const`
+`f`
+`f16c`
+`f32mm`
+`f64mm`
+`faminmax`
+`fcma`
+`fdivdu`
+`fhm`
+`flagm`
+`flagm2`
+`float1e2`
+`float1e3`
+`float3e4`
+`float7e60`
+`floate1`
+`fma`
+`fp-armv8`
+`fp16`
+`fp64`
+`fp8`
+`fp8dot2`
+`fp8dot4`
+`fp8fma`
+`fpuv2_df`
+`fpuv2_sf`
+`fpuv3_df`
+`fpuv3_hf`
+`fpuv3_hi`
+`fpuv3_sf`
+`frecipe`
+`frintts`
+`fxsr`
+`gfni`
+`hard-float`
+`hard-float-abi`
+`hard-tp`
+`hbc`
+`high-registers`
+`hvx`
+`hvx-length128b`
+`hwdiv`
+`i8mm`
+`jsconv`
+`lahfsahf`
+`lasx`
+`lbt`
+`leoncasa`
+`lor`
+`lse`
+`lse128`
+`lse2`
+`lsx`
+`lut`
+`lvz`
+`lzcnt`
+`m`
+`mclass`
+`mops`
+`movbe`
+`mp`
+`mp1e2`
+`msa`
+`mte`
+`multivalue`
+`mutable-globals`
+`neon`
+`nontrapping-fptoint`
+`nvic`
+`paca`
+`pacg`
+`pan`
+`partword-atomics`
+`pauth-lr`
+`pclmulqdq`
+`pmuv3`
+`popcnt`
+`power10-vector`
+`power8-altivec`
+`power8-vector`
+`power9-altivec`
+`power9-vector`
+`prfchw`
+`quadword-atomics`
+`rand`
+`ras`
+`rclass`
+`rcpc`
+`rcpc2`
+`rcpc3`
+`rdm`
+`rdrand`
+`rdseed`
+`reference-types`
+`relax`
+`relaxed-simd`
+`reserve-x18`
+`rtm`
+`sb`
+`sha`
+`sha2`
+`sha3`
+`sha512`
+`sign-ext`
+`simd128`
+`sm3`
+`sm4`
+`sme`
+`sme-b16b16`
+`sme-f16f16`
+`sme-f64f64`
+`sme-f8f16`
+`sme-f8f32`
+`sme-fa64`
+`sme-i16i64`
+`sme-lutv2`
+`sme2`
+`sme2p1`
+`spe`
+`ssbs`
+`sse`
+`sse2`
+`sse3`
+`sse4.1`
+`sse4.2`
+`sse4a`
+`ssse3`
+`ssve-fp8dot2`
+`ssve-fp8dot4`
+`ssve-fp8fma`
+`sve`
+`sve-b16b16`
+`sve2`
+`sve2-aes`
+`sve2-bitperm`
+`sve2-sha3`
+`sve2-sm4`
+`sve2p1`
+`tail-call`
+`tbm`
+`thumb-mode`
+`thumb2`
+`tme`
+`trust`
+`trustzone`
+`ual`
+`unaligned-scalar-mem`
+`v`
+`v5te`
+`v6`
+`v6k`
+`v6t2`
+`v7`
+`v8`
+`v8.1a`
+`v8.2a`
+`v8.3a`
+`v8.4a`
+`v8.5a`
+`v8.6a`
+`v8.7a`
+`v8.8a`
+`v8.9a`
+`v8plus`
+`v9`
+`v9.1a`
+`v9.2a`
+`v9.3a`
+`v9.4a`
+`v9.5a`
+`v9a`
+`vaes`
+`vdsp2e60f`
+`vdspv1`
+`vdspv2`
+`vector`
+`vfp2`
+`vfp3`
+`vfp4`
+`vh`
+`virt`
+`virtualization`
+`vpclmulqdq`
+`vsx`
+`wfxt`
+`wide-arithmetic`
+`xop`
+`xsave`
+`xsavec`
+`xsaveopt`
+`xsaves`
+`zaamo`
+`zabha`
+`zalrsc`
+`zba`
+`zbb`
+`zbc`
+`zbkb`
+`zbkc`
+`zbkx`
+`zbs`
+`zdinx`
+`zfh`
+`zfhmin`
+`zfinx`
+`zhinx`
+`zhinxmin`
+`zk`
+`zkn`
+`zknd`
+`zkne`
+`zknh`
+`zkr`
+`zks`
+`zksed`
+`zksh`, and `zkt`
+   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
+   = note: `#[warn(unexpected_cfgs)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/check-cfg/well-known-values.rs b/tests/ui/check-cfg/well-known-values.rs
index 1fda4b2089ec2..40b7b2db83659 100644
--- a/tests/ui/check-cfg/well-known-values.rs
+++ b/tests/ui/check-cfg/well-known-values.rs
@@ -60,8 +60,8 @@
     //~^ WARN unexpected `cfg` condition value
     target_family = "_UNEXPECTED_VALUE",
     //~^ WARN unexpected `cfg` condition value
-    target_feature = "_UNEXPECTED_VALUE",
-    //~^ WARN unexpected `cfg` condition value
+    // target_feature = "_UNEXPECTED_VALUE",
+    // ^ tested in target_feature.rs
     target_has_atomic = "_UNEXPECTED_VALUE",
     //~^ WARN unexpected `cfg` condition value
     target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr
index 4d375d80e7718..7c03d0570db59 100644
--- a/tests/ui/check-cfg/well-known-values.stderr
+++ b/tests/ui/check-cfg/well-known-values.stderr
@@ -168,15 +168,6 @@ LL |     target_family = "_UNEXPECTED_VALUE",
    = note: expected values for `target_family` are: `unix`, `wasm`, and `windows`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
 
-warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
-  --> $DIR/well-known-values.rs:63:5
-   |
-LL |     target_feature = "_UNEXPECTED_VALUE",
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `cssc`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `ecv`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `faminmax`, `fcma`, `fdivdu`, `fhm`, `flagm`, `flagm2`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fp8`, `fp8dot2`, `fp8dot4`, `fp8fma`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `hbc`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `leoncasa`, `lor`, `lse`, `lse128`, `lse2`, `lsx`, `lut`, `lvz`, `lzcnt`, `m`, `mclass`, `mops`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `partword-atomics`, `pauth-lr`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `quadword-atomics`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rcpc3`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `reserve-x18`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sha512`, `sign-ext`, `simd128`, `sm3`, `sm4`, `sme`, `sme-b16b16`, `sme-f16f16`, `sme-f64f64`, `sme-f8f16`, `sme-f8f32`, `sme-fa64`, `sme-i16i64`, `sme-lutv2`, `sme2`, `sme2p1`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `ssve-fp8dot2`, `ssve-fp8dot4`, `ssve-fp8fma`, `sve`, `sve-b16b16`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `sve2p1`, `tail-call`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `v8.8a`, `v8.9a`, `v8plus`, `v9`, `v9.1a`, `v9.2a`, `v9.3a`, `v9.4a`, `v9.5a`, `v9a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `wfxt`, `wide-arithmetic`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zaamo`, `zabha`, `zalrsc`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt`
-   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
-
 warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
   --> $DIR/well-known-values.rs:65:5
    |
@@ -297,5 +288,5 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
    = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
 
-warning: 30 warnings emitted
+warning: 29 warnings emitted