Skip to content

Commit f546b44

Browse files
authored
Rollup merge of #117981 - Urgau:check-cfg-remove-deprecated-syntax, r=b-naber
Remove deprecated `--check-cfg` syntax This PR removes the deprecated `--check-cfg` `names(...)` and `values(...)` syntax. Follow up to #111072 Part of rust-lang/compiler-team#636 r? compiler
2 parents 7a34091 + 3f0369e commit f546b44

39 files changed

+183
-406
lines changed

compiler/rustc_interface/src/interface.rs

+83-157
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::registry::Registry;
1111
use rustc_errors::{ErrorGuaranteed, Handler};
1212
use rustc_lint::LintStore;
13+
use rustc_middle::ty;
1314
use rustc_middle::util::Providers;
14-
use rustc_middle::{bug, ty};
1515
use rustc_parse::maybe_new_parser_from_source_str;
1616
use rustc_query_impl::QueryCtxt;
1717
use rustc_query_system::query::print_query_stack;
@@ -104,7 +104,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
104104
let exhaustive_values = !specs.is_empty();
105105
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
106106

107-
let mut old_syntax = None;
108107
for s in specs {
109108
let sess = ParseSess::with_silent_emitter(Some(format!(
110109
"this error occurred on the command line: `--check-cfg={s}`"
@@ -142,174 +141,101 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
142141
expected_error();
143142
};
144143

145-
let mut set_old_syntax = || {
146-
// defaults are flipped for the old syntax
147-
if old_syntax == None {
148-
check_cfg.exhaustive_names = false;
149-
check_cfg.exhaustive_values = false;
150-
}
151-
old_syntax = Some(true);
152-
};
153-
154-
if meta_item.has_name(sym::names) {
155-
set_old_syntax();
156-
157-
check_cfg.exhaustive_names = true;
158-
for arg in args {
159-
if arg.is_word()
160-
&& let Some(ident) = arg.ident()
161-
{
162-
check_cfg.expecteds.entry(ident.name).or_insert(ExpectedValues::Any);
163-
} else {
164-
error!("`names()` arguments must be simple identifiers");
165-
}
166-
}
167-
} else if meta_item.has_name(sym::values) {
168-
set_old_syntax();
169-
170-
if let Some((name, values)) = args.split_first() {
171-
if name.is_word()
172-
&& let Some(ident) = name.ident()
173-
{
174-
let expected_values = check_cfg
175-
.expecteds
176-
.entry(ident.name)
177-
.and_modify(|expected_values| match expected_values {
178-
ExpectedValues::Some(_) => {}
179-
ExpectedValues::Any => {
180-
// handle the case where names(...) was done
181-
// before values by changing to a list
182-
*expected_values = ExpectedValues::Some(FxHashSet::default());
183-
}
184-
})
185-
.or_insert_with(|| ExpectedValues::Some(FxHashSet::default()));
144+
if !meta_item.has_name(sym::cfg) {
145+
expected_error();
146+
}
186147

187-
let ExpectedValues::Some(expected_values) = expected_values else {
188-
bug!("`expected_values` should be a list a values")
189-
};
148+
let mut names = Vec::new();
149+
let mut values: FxHashSet<_> = Default::default();
190150

191-
for val in values {
192-
if let Some(LitKind::Str(s, _)) = val.lit().map(|lit| &lit.kind) {
193-
expected_values.insert(Some(*s));
194-
} else {
195-
error!("`values()` arguments must be string literals");
196-
}
197-
}
151+
let mut any_specified = false;
152+
let mut values_specified = false;
153+
let mut values_any_specified = false;
198154

199-
if values.is_empty() {
200-
expected_values.insert(None);
201-
}
202-
} else {
203-
error!("`values()` first argument must be a simple identifier");
155+
for arg in args {
156+
if arg.is_word()
157+
&& let Some(ident) = arg.ident()
158+
{
159+
if values_specified {
160+
error!("`cfg()` names cannot be after values");
204161
}
205-
} else if args.is_empty() {
206-
check_cfg.exhaustive_values = true;
207-
} else {
208-
expected_error();
209-
}
210-
} else if meta_item.has_name(sym::cfg) {
211-
old_syntax = Some(false);
212-
213-
let mut names = Vec::new();
214-
let mut values: FxHashSet<_> = Default::default();
215-
216-
let mut any_specified = false;
217-
let mut values_specified = false;
218-
let mut values_any_specified = false;
219-
220-
for arg in args {
221-
if arg.is_word()
222-
&& let Some(ident) = arg.ident()
223-
{
224-
if values_specified {
225-
error!("`cfg()` names cannot be after values");
226-
}
227-
names.push(ident);
228-
} else if arg.has_name(sym::any)
229-
&& let Some(args) = arg.meta_item_list()
230-
{
231-
if any_specified {
232-
error!("`any()` cannot be specified multiple times");
233-
}
234-
any_specified = true;
235-
if !args.is_empty() {
236-
error!("`any()` must be empty");
237-
}
238-
} else if arg.has_name(sym::values)
239-
&& let Some(args) = arg.meta_item_list()
240-
{
241-
if names.is_empty() {
242-
error!("`values()` cannot be specified before the names");
243-
} else if values_specified {
244-
error!("`values()` cannot be specified multiple times");
245-
}
246-
values_specified = true;
247-
248-
for arg in args {
249-
if let Some(LitKind::Str(s, _)) = arg.lit().map(|lit| &lit.kind) {
250-
values.insert(Some(*s));
251-
} else if arg.has_name(sym::any)
252-
&& let Some(args) = arg.meta_item_list()
253-
{
254-
if values_any_specified {
255-
error!("`any()` in `values()` cannot be specified multiple times");
256-
}
257-
values_any_specified = true;
258-
if !args.is_empty() {
259-
error!("`any()` must be empty");
260-
}
261-
} else {
262-
error!("`values()` arguments must be string literals or `any()`");
162+
names.push(ident);
163+
} else if arg.has_name(sym::any)
164+
&& let Some(args) = arg.meta_item_list()
165+
{
166+
if any_specified {
167+
error!("`any()` cannot be specified multiple times");
168+
}
169+
any_specified = true;
170+
if !args.is_empty() {
171+
error!("`any()` must be empty");
172+
}
173+
} else if arg.has_name(sym::values)
174+
&& let Some(args) = arg.meta_item_list()
175+
{
176+
if names.is_empty() {
177+
error!("`values()` cannot be specified before the names");
178+
} else if values_specified {
179+
error!("`values()` cannot be specified multiple times");
180+
}
181+
values_specified = true;
182+
183+
for arg in args {
184+
if let Some(LitKind::Str(s, _)) = arg.lit().map(|lit| &lit.kind) {
185+
values.insert(Some(*s));
186+
} else if arg.has_name(sym::any)
187+
&& let Some(args) = arg.meta_item_list()
188+
{
189+
if values_any_specified {
190+
error!("`any()` in `values()` cannot be specified multiple times");
191+
}
192+
values_any_specified = true;
193+
if !args.is_empty() {
194+
error!("`any()` must be empty");
263195
}
196+
} else {
197+
error!("`values()` arguments must be string literals or `any()`");
264198
}
265-
} else {
266-
error!(
267-
"`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
268-
);
269199
}
200+
} else {
201+
error!("`cfg()` arguments must be simple identifiers, `any()` or `values(...)`");
270202
}
203+
}
271204

272-
if values.is_empty() && !values_any_specified && !any_specified {
273-
values.insert(None);
274-
} else if !values.is_empty() && values_any_specified {
275-
error!(
276-
"`values()` arguments cannot specify string literals and `any()` at the same time"
277-
);
278-
}
205+
if values.is_empty() && !values_any_specified && !any_specified {
206+
values.insert(None);
207+
} else if !values.is_empty() && values_any_specified {
208+
error!(
209+
"`values()` arguments cannot specify string literals and `any()` at the same time"
210+
);
211+
}
279212

280-
if any_specified {
281-
if names.is_empty()
282-
&& values.is_empty()
283-
&& !values_specified
284-
&& !values_any_specified
285-
{
286-
check_cfg.exhaustive_names = false;
287-
} else {
288-
error!("`cfg(any())` can only be provided in isolation");
289-
}
213+
if any_specified {
214+
if names.is_empty() && values.is_empty() && !values_specified && !values_any_specified {
215+
check_cfg.exhaustive_names = false;
290216
} else {
291-
for name in names {
292-
check_cfg
293-
.expecteds
294-
.entry(name.name)
295-
.and_modify(|v| match v {
296-
ExpectedValues::Some(v) if !values_any_specified => {
297-
v.extend(values.clone())
298-
}
299-
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
300-
ExpectedValues::Any => {}
301-
})
302-
.or_insert_with(|| {
303-
if values_any_specified {
304-
ExpectedValues::Any
305-
} else {
306-
ExpectedValues::Some(values.clone())
307-
}
308-
});
309-
}
217+
error!("`cfg(any())` can only be provided in isolation");
310218
}
311219
} else {
312-
expected_error();
220+
for name in names {
221+
check_cfg
222+
.expecteds
223+
.entry(name.name)
224+
.and_modify(|v| match v {
225+
ExpectedValues::Some(v) if !values_any_specified => {
226+
v.extend(values.clone())
227+
}
228+
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
229+
ExpectedValues::Any => {}
230+
})
231+
.or_insert_with(|| {
232+
if values_any_specified {
233+
ExpectedValues::Any
234+
} else {
235+
ExpectedValues::Some(values.clone())
236+
}
237+
});
238+
}
313239
}
314240
}
315241

compiler/rustc_lint_defs/src/builtin.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,7 @@ declare_lint! {
31353135
/// ### Example
31363136
///
31373137
/// ```text
3138-
/// rustc --check-cfg 'names()'
3138+
/// rustc --check-cfg 'cfg()'
31393139
/// ```
31403140
///
31413141
/// ```rust,ignore (needs command line option)
@@ -3146,7 +3146,7 @@ declare_lint! {
31463146
/// This will produce:
31473147
///
31483148
/// ```text
3149-
/// warning: unknown condition name used
3149+
/// warning: unexpected `cfg` condition name: `widnows`
31503150
/// --> lint_example.rs:1:7
31513151
/// |
31523152
/// 1 | #[cfg(widnows)]
@@ -3157,9 +3157,10 @@ declare_lint! {
31573157
///
31583158
/// ### Explanation
31593159
///
3160-
/// This lint is only active when a `--check-cfg='names(...)'` option has been passed
3161-
/// to the compiler and triggers whenever an unknown condition name or value is used.
3162-
/// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
3160+
/// This lint is only active when `--check-cfg` arguments are being passed
3161+
/// to the compiler and triggers whenever an unexpected condition name or value is used.
3162+
///
3163+
/// The known condition include names or values passed in `--check-cfg`, and some
31633164
/// well-knows names and values built into the compiler.
31643165
pub UNEXPECTED_CFGS,
31653166
Warn,

compiler/rustc_llvm/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn output(cmd: &mut Command) -> String {
102102

103103
fn main() {
104104
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
105-
println!("cargo:rustc-check-cfg=values(llvm_component,\"{component}\")");
105+
println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))");
106106
}
107107

108108
if tracked_env_var_os("RUST_CHECK").is_some() {

src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
370370

371371
[[package]]
372372
name = "libc"
373-
version = "0.2.149"
373+
version = "0.2.150"
374374
source = "registry+https://github.com/rust-lang/crates.io-index"
375-
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
375+
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
376376

377377
[[package]]
378378
name = "linux-raw-sys"

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ filetime = "0.2"
4242
hex = "0.4"
4343
home = "0.5.4"
4444
ignore = "0.4.10"
45-
libc = "0.2"
45+
libc = "0.2.150"
4646
object = { version = "0.32.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
4747
once_cell = "1.7.2"
4848
opener = "0.5"

0 commit comments

Comments
 (0)