Skip to content

Commit 0383ca3

Browse files
committed
Prevent mixing deprecated check-cfg syntax with new one
1 parent b975854 commit 0383ca3

13 files changed

+80
-95
lines changed

compiler/rustc_interface/src/interface.rs

+9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
146146
error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`")
147147
};
148148

149+
let cannot_mix_error = || {
150+
error!("cannot mix `cfg(...)` with deprecated syntax `names(...)` and `values(...)`")
151+
};
152+
149153
let Ok(mut parser) = maybe_new_parser_from_source_str(&sess, filename, s.to_string())
150154
else {
151155
expected_error();
@@ -169,6 +173,8 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
169173
if old_syntax == None {
170174
check_cfg.exhaustive_names = false;
171175
check_cfg.exhaustive_values = false;
176+
} else if old_syntax == Some(false) {
177+
cannot_mix_error();
172178
}
173179
old_syntax = Some(true);
174180
};
@@ -226,6 +232,9 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
226232
expected_error();
227233
}
228234
} else if meta_item.has_name(sym::cfg) {
235+
if old_syntax == Some(true) {
236+
cannot_mix_error();
237+
}
229238
old_syntax = Some(false);
230239

231240
let mut names = Vec::new();

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)