Skip to content

Commit 15c3b76

Browse files
authored
Rollup merge of rust-lang#117025 - Urgau:cleanup-improve-check-cfg-impl, r=petrochenkov
Cleanup and improve `--check-cfg` implementation This PR removes some indentation in the code, as well as preventing some bugs/misusages and fix a nit in the doc. r? ``@petrochenkov`` (maybe)
2 parents f8807cc + e2122e7 commit 15c3b76

17 files changed

+277
-297
lines changed

compiler/rustc_interface/src/interface.rs

+198-200
Large diffs are not rendered by default.

src/doc/unstable-book/src/compiler-flags/check-cfg.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn do_mumble_frotz() {}
139139

140140
```bash
141141
# This turns on checking for feature values, but not for condition names.
142-
rustc --check-cfg 'configure(feature, values("zapping", "lasers"))' \
142+
rustc --check-cfg 'cfg(feature, values("zapping", "lasers"))' \
143143
--check-cfg 'cfg(any())' \
144144
--cfg 'feature="zapping"' -Z unstable-options
145145
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: invalid `--check-cfg` argument: `cfg(any(),values())` (`values()` cannot be specified before the names)
2+

tests/ui/check-cfg/invalid-arguments.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// revisions: multiple_values_any not_empty_any not_empty_values_any
77
// revisions: values_any_missing_values values_any_before_ident ident_in_values_1
88
// revisions: ident_in_values_2 unknown_meta_item_1 unknown_meta_item_2 unknown_meta_item_3
9-
// revisions: mixed_values_any mixed_any giberich
9+
// revisions: mixed_values_any mixed_any any_values giberich unterminated
1010
//
1111
// compile-flags: -Z unstable-options
1212
// [anything_else]compile-flags: --check-cfg=anything_else(...)
@@ -29,6 +29,8 @@
2929
// [unknown_meta_item_3]compile-flags: --check-cfg=cfg(foo,values(test()))
3030
// [mixed_values_any]compile-flags: --check-cfg=cfg(foo,values("bar",any()))
3131
// [mixed_any]compile-flags: --check-cfg=cfg(any(),values(any()))
32+
// [any_values]compile-flags: --check-cfg=cfg(any(),values())
3233
// [giberich]compile-flags: --check-cfg=cfg(...)
34+
// [unterminated]compile-flags: --check-cfg=cfg(
3335

3436
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: invalid `--check-cfg` argument: `cfg(` (expected `cfg(name, values("value1", "value2", ... "valueN"))`)
2+

tests/ui/check-cfg/mix.cfg.stderr

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
warning: unexpected `cfg` condition name: `widnows`
2-
--> $DIR/mix.rs:15:7
2+
--> $DIR/mix.rs:16: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

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

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

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

3333
warning: unexpected `cfg` condition name: `uu`
34-
--> $DIR/mix.rs:34:12
34+
--> $DIR/mix.rs:35:12
3535
|
3636
LL | #[cfg_attr(uu, test)]
3737
| ^^
@@ -47,141 +47,141 @@ warning: unexpected `unknown_name` as condition name
4747
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
4848

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

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

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

7171
warning: unexpected `cfg` condition name: `xxx`
72-
--> $DIR/mix.rs:50:10
72+
--> $DIR/mix.rs:51:10
7373
|
7474
LL | cfg!(xxx = "foo");
7575
| ^^^^^^^^^^^
7676

7777
warning: unexpected `cfg` condition name: `xxx`
78-
--> $DIR/mix.rs:52:10
78+
--> $DIR/mix.rs:53:10
7979
|
8080
LL | cfg!(xxx);
8181
| ^^^
8282

8383
warning: unexpected `cfg` condition name: `xxx`
84-
--> $DIR/mix.rs:54:14
84+
--> $DIR/mix.rs:55:14
8585
|
8686
LL | cfg!(any(xxx, windows));
8787
| ^^^
8888

8989
warning: unexpected `cfg` condition value: `bad`
90-
--> $DIR/mix.rs:56:14
90+
--> $DIR/mix.rs:57:14
9191
|
9292
LL | cfg!(any(feature = "bad", windows));
9393
| ^^^^^^^^^^^^^^^
9494
|
9595
= note: expected values for `feature` are: `foo`
9696

9797
warning: unexpected `cfg` condition name: `xxx`
98-
--> $DIR/mix.rs:58:23
98+
--> $DIR/mix.rs:59:23
9999
|
100100
LL | cfg!(any(windows, xxx));
101101
| ^^^
102102

103103
warning: unexpected `cfg` condition name: `xxx`
104-
--> $DIR/mix.rs:60:20
104+
--> $DIR/mix.rs:61:20
105105
|
106106
LL | cfg!(all(unix, xxx));
107107
| ^^^
108108

109109
warning: unexpected `cfg` condition name: `aa`
110-
--> $DIR/mix.rs:62:14
110+
--> $DIR/mix.rs:63:14
111111
|
112112
LL | cfg!(all(aa, bb));
113113
| ^^
114114

115115
warning: unexpected `cfg` condition name: `bb`
116-
--> $DIR/mix.rs:62:18
116+
--> $DIR/mix.rs:63:18
117117
|
118118
LL | cfg!(all(aa, bb));
119119
| ^^
120120

121121
warning: unexpected `cfg` condition name: `aa`
122-
--> $DIR/mix.rs:65:14
122+
--> $DIR/mix.rs:66:14
123123
|
124124
LL | cfg!(any(aa, bb));
125125
| ^^
126126

127127
warning: unexpected `cfg` condition name: `bb`
128-
--> $DIR/mix.rs:65:18
128+
--> $DIR/mix.rs:66:18
129129
|
130130
LL | cfg!(any(aa, bb));
131131
| ^^
132132

133133
warning: unexpected `cfg` condition value: `zebra`
134-
--> $DIR/mix.rs:68:20
134+
--> $DIR/mix.rs:69:20
135135
|
136136
LL | cfg!(any(unix, feature = "zebra"));
137137
| ^^^^^^^^^^^^^^^^^
138138
|
139139
= note: expected values for `feature` are: `foo`
140140

141141
warning: unexpected `cfg` condition name: `xxx`
142-
--> $DIR/mix.rs:70:14
142+
--> $DIR/mix.rs:71:14
143143
|
144144
LL | cfg!(any(xxx, feature = "zebra"));
145145
| ^^^
146146

147147
warning: unexpected `cfg` condition value: `zebra`
148-
--> $DIR/mix.rs:70:19
148+
--> $DIR/mix.rs:71:19
149149
|
150150
LL | cfg!(any(xxx, feature = "zebra"));
151151
| ^^^^^^^^^^^^^^^^^
152152
|
153153
= note: expected values for `feature` are: `foo`
154154

155155
warning: unexpected `cfg` condition name: `xxx`
156-
--> $DIR/mix.rs:73:14
156+
--> $DIR/mix.rs:74:14
157157
|
158158
LL | cfg!(any(xxx, unix, xxx));
159159
| ^^^
160160

161161
warning: unexpected `cfg` condition name: `xxx`
162-
--> $DIR/mix.rs:73:25
162+
--> $DIR/mix.rs:74:25
163163
|
164164
LL | cfg!(any(xxx, unix, xxx));
165165
| ^^^
166166

167167
warning: unexpected `cfg` condition value: `zebra`
168-
--> $DIR/mix.rs:76:14
168+
--> $DIR/mix.rs:77:14
169169
|
170170
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
171171
| ^^^^^^^^^^^^^^^^^
172172
|
173173
= note: expected values for `feature` are: `foo`
174174

175175
warning: unexpected `cfg` condition value: `zebra`
176-
--> $DIR/mix.rs:76:33
176+
--> $DIR/mix.rs:77:33
177177
|
178178
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
179179
| ^^^^^^^^^^^^^^^^^
180180
|
181181
= note: expected values for `feature` are: `foo`
182182

183183
warning: unexpected `cfg` condition value: `zebra`
184-
--> $DIR/mix.rs:76:52
184+
--> $DIR/mix.rs:77:52
185185
|
186186
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
187187
| ^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)