Skip to content

Commit 88c6f3d

Browse files
committed
Limit the number of names and values in check-cfg diagnostics
1 parent d2e8ecd commit 88c6f3d

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

Diff for: compiler/rustc_lint/src/context/diagnostics.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use rustc_span::edit_distance::find_best_match_for_name;
99
use rustc_span::symbol::{sym, Symbol};
1010
use rustc_span::BytePos;
1111

12+
const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;
13+
1214
pub(super) fn builtin(
1315
sess: &Session,
1416
diagnostic: BuiltinLintDiagnostics,
@@ -291,7 +293,8 @@ pub(super) fn builtin(
291293
);
292294
}
293295
}
294-
if !possibilities.is_empty() {
296+
if !possibilities.is_empty() && possibilities.len() <= MAX_CHECK_CFG_NAMES_OR_VALUES
297+
{
295298
let mut possibilities =
296299
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
297300
possibilities.sort();
@@ -345,6 +348,10 @@ pub(super) fn builtin(
345348
// Show the full list if all possible values for a given name, but don't do it
346349
// for names as the possibilities could be very long
347350
if !possibilities.is_empty() {
351+
if possibilities.len() <= MAX_CHECK_CFG_NAMES_OR_VALUES
352+
// as an anti-regression test `tests/ui/check-cfg/well-known-values.rs`
353+
// needs to have the full list of expected values, so we use this dummy env
354+
|| std::env::var("RUSTC_PRINT_FULL_CHECK_CFG").is_ok()
348355
{
349356
let mut possibilities =
350357
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();

Diff for: tests/ui/check-cfg/mix.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ fn test_cfg_macro() {
7474
//~^ WARNING unexpected `cfg` condition value
7575
//~| WARNING unexpected `cfg` condition value
7676
//~| WARNING unexpected `cfg` condition value
77+
cfg!(target_feature = "zebra");
78+
//~^ WARNING unexpected `cfg` condition value
7779
}
7880

7981
fn main() {}

Diff for: tests/ui/check-cfg/mix.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,13 @@ LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
245245
= help: to expect this configuration use `--check-cfg=cfg(feature, values("zebra"))`
246246
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
247247

248-
warning: 26 warnings emitted
248+
warning: unexpected `cfg` condition value: `zebra`
249+
--> $DIR/mix.rs:77:10
250+
|
251+
LL | cfg!(target_feature = "zebra");
252+
| ^^^^^^^^^^^^^^^^^^^^^^^^
253+
|
254+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
255+
256+
warning: 27 warnings emitted
249257

Diff for: tests/ui/check-cfg/well-known-values.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
// check-pass
88
// compile-flags: --check-cfg=cfg() -Z unstable-options
9+
// rustc-env:RUSTC_PRINT_FULL_CHECK_CFG=1
910

1011
#![feature(cfg_overflow_checks)]
1112
#![feature(cfg_relocation_model)]

Diff for: tests/ui/check-cfg/well-known-values.stderr

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
2-
--> $DIR/well-known-values.rs:26:5
2+
--> $DIR/well-known-values.rs:27:5
33
|
44
LL | clippy = "_UNEXPECTED_VALUE",
55
| ^^^^^^----------------------
@@ -11,7 +11,7 @@ LL | clippy = "_UNEXPECTED_VALUE",
1111
= note: `#[warn(unexpected_cfgs)]` on by default
1212

1313
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
14-
--> $DIR/well-known-values.rs:28:5
14+
--> $DIR/well-known-values.rs:29:5
1515
|
1616
LL | debug_assertions = "_UNEXPECTED_VALUE",
1717
| ^^^^^^^^^^^^^^^^----------------------
@@ -22,7 +22,7 @@ LL | debug_assertions = "_UNEXPECTED_VALUE",
2222
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
2323

2424
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
25-
--> $DIR/well-known-values.rs:30:5
25+
--> $DIR/well-known-values.rs:31:5
2626
|
2727
LL | doc = "_UNEXPECTED_VALUE",
2828
| ^^^----------------------
@@ -33,7 +33,7 @@ LL | doc = "_UNEXPECTED_VALUE",
3333
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
3434

3535
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
36-
--> $DIR/well-known-values.rs:32:5
36+
--> $DIR/well-known-values.rs:33:5
3737
|
3838
LL | doctest = "_UNEXPECTED_VALUE",
3939
| ^^^^^^^----------------------
@@ -44,7 +44,7 @@ LL | doctest = "_UNEXPECTED_VALUE",
4444
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
4545

4646
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
47-
--> $DIR/well-known-values.rs:34:5
47+
--> $DIR/well-known-values.rs:35:5
4848
|
4949
LL | miri = "_UNEXPECTED_VALUE",
5050
| ^^^^----------------------
@@ -55,7 +55,7 @@ LL | miri = "_UNEXPECTED_VALUE",
5555
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
5656

5757
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
58-
--> $DIR/well-known-values.rs:36:5
58+
--> $DIR/well-known-values.rs:37:5
5959
|
6060
LL | overflow_checks = "_UNEXPECTED_VALUE",
6161
| ^^^^^^^^^^^^^^^----------------------
@@ -66,7 +66,7 @@ LL | overflow_checks = "_UNEXPECTED_VALUE",
6666
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
6767

6868
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
69-
--> $DIR/well-known-values.rs:38:5
69+
--> $DIR/well-known-values.rs:39:5
7070
|
7171
LL | panic = "_UNEXPECTED_VALUE",
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -75,7 +75,7 @@ LL | panic = "_UNEXPECTED_VALUE",
7575
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
7676

7777
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
78-
--> $DIR/well-known-values.rs:40:5
78+
--> $DIR/well-known-values.rs:41:5
7979
|
8080
LL | proc_macro = "_UNEXPECTED_VALUE",
8181
| ^^^^^^^^^^----------------------
@@ -86,7 +86,7 @@ LL | proc_macro = "_UNEXPECTED_VALUE",
8686
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
8787

8888
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
89-
--> $DIR/well-known-values.rs:42:5
89+
--> $DIR/well-known-values.rs:43:5
9090
|
9191
LL | relocation_model = "_UNEXPECTED_VALUE",
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,7 +95,7 @@ LL | relocation_model = "_UNEXPECTED_VALUE",
9595
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
9696

9797
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
98-
--> $DIR/well-known-values.rs:44:5
98+
--> $DIR/well-known-values.rs:45:5
9999
|
100100
LL | sanitize = "_UNEXPECTED_VALUE",
101101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -104,7 +104,7 @@ LL | sanitize = "_UNEXPECTED_VALUE",
104104
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
105105

106106
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
107-
--> $DIR/well-known-values.rs:46:5
107+
--> $DIR/well-known-values.rs:47:5
108108
|
109109
LL | target_abi = "_UNEXPECTED_VALUE",
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -113,7 +113,7 @@ LL | target_abi = "_UNEXPECTED_VALUE",
113113
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
114114

115115
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
116-
--> $DIR/well-known-values.rs:48:5
116+
--> $DIR/well-known-values.rs:49:5
117117
|
118118
LL | target_arch = "_UNEXPECTED_VALUE",
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -122,7 +122,7 @@ LL | target_arch = "_UNEXPECTED_VALUE",
122122
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
123123

124124
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
125-
--> $DIR/well-known-values.rs:50:5
125+
--> $DIR/well-known-values.rs:51:5
126126
|
127127
LL | target_endian = "_UNEXPECTED_VALUE",
128128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -131,7 +131,7 @@ LL | target_endian = "_UNEXPECTED_VALUE",
131131
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
132132

133133
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
134-
--> $DIR/well-known-values.rs:52:5
134+
--> $DIR/well-known-values.rs:53:5
135135
|
136136
LL | target_env = "_UNEXPECTED_VALUE",
137137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -140,7 +140,7 @@ LL | target_env = "_UNEXPECTED_VALUE",
140140
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
141141

142142
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
143-
--> $DIR/well-known-values.rs:54:5
143+
--> $DIR/well-known-values.rs:55:5
144144
|
145145
LL | target_family = "_UNEXPECTED_VALUE",
146146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -149,7 +149,7 @@ LL | target_family = "_UNEXPECTED_VALUE",
149149
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
150150

151151
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
152-
--> $DIR/well-known-values.rs:56:5
152+
--> $DIR/well-known-values.rs:57:5
153153
|
154154
LL | target_feature = "_UNEXPECTED_VALUE",
155155
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -158,7 +158,7 @@ LL | target_feature = "_UNEXPECTED_VALUE",
158158
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
159159

160160
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
161-
--> $DIR/well-known-values.rs:58:5
161+
--> $DIR/well-known-values.rs:59:5
162162
|
163163
LL | target_has_atomic = "_UNEXPECTED_VALUE",
164164
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -167,7 +167,7 @@ LL | target_has_atomic = "_UNEXPECTED_VALUE",
167167
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
168168

169169
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
170-
--> $DIR/well-known-values.rs:60:5
170+
--> $DIR/well-known-values.rs:61:5
171171
|
172172
LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
173173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -176,7 +176,7 @@ LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
176176
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
177177

178178
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
179-
--> $DIR/well-known-values.rs:62:5
179+
--> $DIR/well-known-values.rs:63:5
180180
|
181181
LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE",
182182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -185,7 +185,7 @@ LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE",
185185
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
186186

187187
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
188-
--> $DIR/well-known-values.rs:64:5
188+
--> $DIR/well-known-values.rs:65:5
189189
|
190190
LL | target_os = "_UNEXPECTED_VALUE",
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -194,7 +194,7 @@ LL | target_os = "_UNEXPECTED_VALUE",
194194
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
195195

196196
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
197-
--> $DIR/well-known-values.rs:66:5
197+
--> $DIR/well-known-values.rs:67:5
198198
|
199199
LL | target_pointer_width = "_UNEXPECTED_VALUE",
200200
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -203,7 +203,7 @@ LL | target_pointer_width = "_UNEXPECTED_VALUE",
203203
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
204204

205205
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
206-
--> $DIR/well-known-values.rs:68:5
206+
--> $DIR/well-known-values.rs:69:5
207207
|
208208
LL | target_thread_local = "_UNEXPECTED_VALUE",
209209
| ^^^^^^^^^^^^^^^^^^^----------------------
@@ -214,7 +214,7 @@ LL | target_thread_local = "_UNEXPECTED_VALUE",
214214
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
215215

216216
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
217-
--> $DIR/well-known-values.rs:70:5
217+
--> $DIR/well-known-values.rs:71:5
218218
|
219219
LL | target_vendor = "_UNEXPECTED_VALUE",
220220
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -223,7 +223,7 @@ LL | target_vendor = "_UNEXPECTED_VALUE",
223223
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
224224

225225
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
226-
--> $DIR/well-known-values.rs:72:5
226+
--> $DIR/well-known-values.rs:73:5
227227
|
228228
LL | test = "_UNEXPECTED_VALUE",
229229
| ^^^^----------------------
@@ -234,7 +234,7 @@ LL | test = "_UNEXPECTED_VALUE",
234234
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
235235

236236
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
237-
--> $DIR/well-known-values.rs:74:5
237+
--> $DIR/well-known-values.rs:75:5
238238
|
239239
LL | unix = "_UNEXPECTED_VALUE",
240240
| ^^^^----------------------
@@ -245,7 +245,7 @@ LL | unix = "_UNEXPECTED_VALUE",
245245
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
246246

247247
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
248-
--> $DIR/well-known-values.rs:76:5
248+
--> $DIR/well-known-values.rs:77:5
249249
|
250250
LL | windows = "_UNEXPECTED_VALUE",
251251
| ^^^^^^^----------------------
@@ -256,7 +256,7 @@ LL | windows = "_UNEXPECTED_VALUE",
256256
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
257257

258258
warning: unexpected `cfg` condition value: `linuz`
259-
--> $DIR/well-known-values.rs:82:7
259+
--> $DIR/well-known-values.rs:83:7
260260
|
261261
LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
262262
| ^^^^^^^^^^^^-------

0 commit comments

Comments
 (0)