Skip to content

Commit 074c547

Browse files
committed
check-cfg: mention the unexpected name and value in the primary message
1 parent cc12a08 commit 074c547

17 files changed

+62
-58
lines changed

compiler/rustc_attr/src/builtin.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,11 @@ pub fn cfg_matches(
548548
UNEXPECTED_CFGS,
549549
cfg.span,
550550
lint_node_id,
551-
"unexpected `cfg` condition value",
551+
if let Some(value) = cfg.value {
552+
format!("unexpected `cfg` condition value: `{}`", value.as_str())
553+
} else {
554+
format!("unexpected `cfg` condition value: (none)")
555+
},
552556
BuiltinLintDiagnostics::UnexpectedCfgValue(
553557
(cfg.name, cfg.name_span),
554558
cfg.value.map(|v| (v, cfg.value_span.unwrap())),
@@ -560,7 +564,7 @@ pub fn cfg_matches(
560564
UNEXPECTED_CFGS,
561565
cfg.span,
562566
lint_node_id,
563-
"unexpected `cfg` condition name",
567+
format!("unexpected `cfg` condition name: `{}`", cfg.name.as_str()),
564568
BuiltinLintDiagnostics::UnexpectedCfgName(
565569
(cfg.name, cfg.name_span),
566570
cfg.value.map(|v| (v, cfg.value_span.unwrap())),

tests/ui/check-cfg/allow-same-level.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `FALSE`
22
--> $DIR/allow-same-level.rs:7:7
33
|
44
LL | #[cfg(FALSE)]

tests/ui/check-cfg/compact-names.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `target_architecture`
22
--> $DIR/compact-names.rs:11:28
33
|
44
LL | #[cfg(target(os = "linux", architecture = "arm"))]

tests/ui/check-cfg/compact-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: `X`
22
--> $DIR/compact-values.rs:11:28
33
|
44
LL | #[cfg(target(os = "linux", arch = "X"))]

tests/ui/check-cfg/diagnotics.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `featur`
22
--> $DIR/diagnotics.rs:4:7
33
|
44
LL | #[cfg(featur)]
@@ -7,7 +7,7 @@ LL | #[cfg(featur)]
77
= help: expected values for `feature` are: `foo`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

10-
warning: unexpected `cfg` condition name
10+
warning: unexpected `cfg` condition name: `featur`
1111
--> $DIR/diagnotics.rs:8:7
1212
|
1313
LL | #[cfg(featur = "foo")]
@@ -18,7 +18,7 @@ help: there is a config with a similar name and value
1818
LL | #[cfg(feature = "foo")]
1919
| ~~~~~~~
2020

21-
warning: unexpected `cfg` condition name
21+
warning: unexpected `cfg` condition name: `featur`
2222
--> $DIR/diagnotics.rs:12:7
2323
|
2424
LL | #[cfg(featur = "fo")]
@@ -30,13 +30,13 @@ help: there is a config with a similar name and different values
3030
LL | #[cfg(feature = "foo")]
3131
| ~~~~~~~~~~~~~~~
3232

33-
warning: unexpected `cfg` condition name
33+
warning: unexpected `cfg` condition name: `no_value`
3434
--> $DIR/diagnotics.rs:19:7
3535
|
3636
LL | #[cfg(no_value)]
3737
| ^^^^^^^^ help: there is a config with a similar name: `no_values`
3838

39-
warning: unexpected `cfg` condition name
39+
warning: unexpected `cfg` condition name: `no_value`
4040
--> $DIR/diagnotics.rs:23:7
4141
|
4242
LL | #[cfg(no_value = "foo")]
@@ -47,7 +47,7 @@ help: there is a config with a similar name and no value
4747
LL | #[cfg(no_values)]
4848
| ~~~~~~~~~
4949

50-
warning: unexpected `cfg` condition value
50+
warning: unexpected `cfg` condition value: `bar`
5151
--> $DIR/diagnotics.rs:27:7
5252
|
5353
LL | #[cfg(no_values = "bar")]

tests/ui/check-cfg/empty-names.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `unknown_key`
22
--> $DIR/empty-names.rs:6:7
33
|
44
LL | #[cfg(unknown_key = "value")]

tests/ui/check-cfg/empty-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: `value`
22
--> $DIR/empty-values.rs:6:7
33
|
44
LL | #[cfg(test = "value")]

tests/ui/check-cfg/invalid-cfg-name.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `widnows`
22
--> $DIR/invalid-cfg-name.rs:7:7
33
|
44
LL | #[cfg(widnows)]

tests/ui/check-cfg/invalid-cfg-value.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: `sedre`
22
--> $DIR/invalid-cfg-value.rs:7:7
33
|
44
LL | #[cfg(feature = "sedre")]
@@ -9,7 +9,7 @@ LL | #[cfg(feature = "sedre")]
99
= note: expected values for `feature` are: `full`, `serde`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

12-
warning: unexpected `cfg` condition value
12+
warning: unexpected `cfg` condition value: `rand`
1313
--> $DIR/invalid-cfg-value.rs:14:7
1414
|
1515
LL | #[cfg(feature = "rand")]

tests/ui/check-cfg/mix.stderr

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
warning: unexpected `cfg` condition name
1+
warning: unexpected `cfg` condition name: `widnows`
22
--> $DIR/mix.rs:11:7
33
|
44
LL | #[cfg(widnows)]
55
| ^^^^^^^ help: there is a config with a similar name: `windows`
66
|
77
= note: `#[warn(unexpected_cfgs)]` on by default
88

9-
warning: unexpected `cfg` condition value
9+
warning: unexpected `cfg` condition value: (none)
1010
--> $DIR/mix.rs:15:7
1111
|
1212
LL | #[cfg(feature)]
1313
| ^^^^^^^- help: specify a config value: `= "foo"`
1414
|
1515
= note: expected values for `feature` are: `foo`
1616

17-
warning: unexpected `cfg` condition value
17+
warning: unexpected `cfg` condition value: `bar`
1818
--> $DIR/mix.rs:22:7
1919
|
2020
LL | #[cfg(feature = "bar")]
2121
| ^^^^^^^^^^^^^^^
2222
|
2323
= note: expected values for `feature` are: `foo`
2424

25-
warning: unexpected `cfg` condition value
25+
warning: unexpected `cfg` condition value: `zebra`
2626
--> $DIR/mix.rs:26:7
2727
|
2828
LL | #[cfg(feature = "zebra")]
2929
| ^^^^^^^^^^^^^^^^^
3030
|
3131
= note: expected values for `feature` are: `foo`
3232

33-
warning: unexpected `cfg` condition name
33+
warning: unexpected `cfg` condition name: `uu`
3434
--> $DIR/mix.rs:30:12
3535
|
3636
LL | #[cfg_attr(uu, test)]
@@ -46,165 +46,165 @@ warning: unexpected `unknown_name` as condition name
4646
|
4747
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
4848

49-
warning: unexpected `cfg` condition name
49+
warning: unexpected `cfg` condition name: `widnows`
5050
--> $DIR/mix.rs:39:10
5151
|
5252
LL | cfg!(widnows);
5353
| ^^^^^^^ help: there is a config with a similar name: `windows`
5454

55-
warning: unexpected `cfg` condition value
55+
warning: unexpected `cfg` condition value: `bar`
5656
--> $DIR/mix.rs:42:10
5757
|
5858
LL | cfg!(feature = "bar");
5959
| ^^^^^^^^^^^^^^^
6060
|
6161
= note: expected values for `feature` are: `foo`
6262

63-
warning: unexpected `cfg` condition value
63+
warning: unexpected `cfg` condition value: `zebra`
6464
--> $DIR/mix.rs:44:10
6565
|
6666
LL | cfg!(feature = "zebra");
6767
| ^^^^^^^^^^^^^^^^^
6868
|
6969
= note: expected values for `feature` are: `foo`
7070

71-
warning: unexpected `cfg` condition name
71+
warning: unexpected `cfg` condition name: `xxx`
7272
--> $DIR/mix.rs:46:10
7373
|
7474
LL | cfg!(xxx = "foo");
7575
| ^^^^^^^^^^^
7676
|
7777
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
7878

79-
warning: unexpected `cfg` condition name
79+
warning: unexpected `cfg` condition name: `xxx`
8080
--> $DIR/mix.rs:48:10
8181
|
8282
LL | cfg!(xxx);
8383
| ^^^
8484
|
8585
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
8686

87-
warning: unexpected `cfg` condition name
87+
warning: unexpected `cfg` condition name: `xxx`
8888
--> $DIR/mix.rs:50:14
8989
|
9090
LL | cfg!(any(xxx, windows));
9191
| ^^^
9292
|
9393
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
9494

95-
warning: unexpected `cfg` condition value
95+
warning: unexpected `cfg` condition value: `bad`
9696
--> $DIR/mix.rs:52:14
9797
|
9898
LL | cfg!(any(feature = "bad", windows));
9999
| ^^^^^^^^^^^^^^^
100100
|
101101
= note: expected values for `feature` are: `foo`
102102

103-
warning: unexpected `cfg` condition name
103+
warning: unexpected `cfg` condition name: `xxx`
104104
--> $DIR/mix.rs:54:23
105105
|
106106
LL | cfg!(any(windows, xxx));
107107
| ^^^
108108
|
109109
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
110110

111-
warning: unexpected `cfg` condition name
111+
warning: unexpected `cfg` condition name: `xxx`
112112
--> $DIR/mix.rs:56:20
113113
|
114114
LL | cfg!(all(unix, xxx));
115115
| ^^^
116116
|
117117
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
118118

119-
warning: unexpected `cfg` condition name
119+
warning: unexpected `cfg` condition name: `aa`
120120
--> $DIR/mix.rs:58:14
121121
|
122122
LL | cfg!(all(aa, bb));
123123
| ^^
124124
|
125125
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
126126

127-
warning: unexpected `cfg` condition name
127+
warning: unexpected `cfg` condition name: `bb`
128128
--> $DIR/mix.rs:58:18
129129
|
130130
LL | cfg!(all(aa, bb));
131131
| ^^
132132
|
133133
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
134134

135-
warning: unexpected `cfg` condition name
135+
warning: unexpected `cfg` condition name: `aa`
136136
--> $DIR/mix.rs:61:14
137137
|
138138
LL | cfg!(any(aa, bb));
139139
| ^^
140140
|
141141
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
142142

143-
warning: unexpected `cfg` condition name
143+
warning: unexpected `cfg` condition name: `bb`
144144
--> $DIR/mix.rs:61:18
145145
|
146146
LL | cfg!(any(aa, bb));
147147
| ^^
148148
|
149149
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
150150

151-
warning: unexpected `cfg` condition value
151+
warning: unexpected `cfg` condition value: `zebra`
152152
--> $DIR/mix.rs:64:20
153153
|
154154
LL | cfg!(any(unix, feature = "zebra"));
155155
| ^^^^^^^^^^^^^^^^^
156156
|
157157
= note: expected values for `feature` are: `foo`
158158

159-
warning: unexpected `cfg` condition name
159+
warning: unexpected `cfg` condition name: `xxx`
160160
--> $DIR/mix.rs:66:14
161161
|
162162
LL | cfg!(any(xxx, feature = "zebra"));
163163
| ^^^
164164
|
165165
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
166166

167-
warning: unexpected `cfg` condition value
167+
warning: unexpected `cfg` condition value: `zebra`
168168
--> $DIR/mix.rs:66:19
169169
|
170170
LL | cfg!(any(xxx, feature = "zebra"));
171171
| ^^^^^^^^^^^^^^^^^
172172
|
173173
= note: expected values for `feature` are: `foo`
174174

175-
warning: unexpected `cfg` condition name
175+
warning: unexpected `cfg` condition name: `xxx`
176176
--> $DIR/mix.rs:69:14
177177
|
178178
LL | cfg!(any(xxx, unix, xxx));
179179
| ^^^
180180
|
181181
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
182182

183-
warning: unexpected `cfg` condition name
183+
warning: unexpected `cfg` condition name: `xxx`
184184
--> $DIR/mix.rs:69:25
185185
|
186186
LL | cfg!(any(xxx, unix, xxx));
187187
| ^^^
188188
|
189189
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
190190

191-
warning: unexpected `cfg` condition value
191+
warning: unexpected `cfg` condition value: `zebra`
192192
--> $DIR/mix.rs:72:14
193193
|
194194
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
195195
| ^^^^^^^^^^^^^^^^^
196196
|
197197
= note: expected values for `feature` are: `foo`
198198

199-
warning: unexpected `cfg` condition value
199+
warning: unexpected `cfg` condition value: `zebra`
200200
--> $DIR/mix.rs:72:33
201201
|
202202
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
203203
| ^^^^^^^^^^^^^^^^^
204204
|
205205
= note: expected values for `feature` are: `foo`
206206

207-
warning: unexpected `cfg` condition value
207+
warning: unexpected `cfg` condition value: `zebra`
208208
--> $DIR/mix.rs:72:52
209209
|
210210
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));

tests/ui/check-cfg/no-values.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: `foo`
22
--> $DIR/no-values.rs:6:7
33
|
44
LL | #[cfg(feature = "foo")]
@@ -9,7 +9,7 @@ LL | #[cfg(feature = "foo")]
99
= note: no expected value for `feature`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

12-
warning: unexpected `cfg` condition value
12+
warning: unexpected `cfg` condition value: `foo`
1313
--> $DIR/no-values.rs:10:7
1414
|
1515
LL | #[cfg(test = "foo")]

tests/ui/check-cfg/order-independant.names_after.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: (none)
22
--> $DIR/order-independant.rs:8:7
33
|
44
LL | #[cfg(a)]
@@ -7,7 +7,7 @@ LL | #[cfg(a)]
77
= note: expected values for `a` are: `b`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

10-
warning: unexpected `cfg` condition value
10+
warning: unexpected `cfg` condition value: `unk`
1111
--> $DIR/order-independant.rs:12:7
1212
|
1313
LL | #[cfg(a = "unk")]

tests/ui/check-cfg/order-independant.names_before.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unexpected `cfg` condition value
1+
warning: unexpected `cfg` condition value: (none)
22
--> $DIR/order-independant.rs:8:7
33
|
44
LL | #[cfg(a)]
@@ -7,7 +7,7 @@ LL | #[cfg(a)]
77
= note: expected values for `a` are: `b`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

10-
warning: unexpected `cfg` condition value
10+
warning: unexpected `cfg` condition value: `unk`
1111
--> $DIR/order-independant.rs:12:7
1212
|
1313
LL | #[cfg(a = "unk")]

0 commit comments

Comments
 (0)