Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mixing deprecated check-cfg syntax with new one #117612

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2215,9 +2215,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"

[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`")
};

let cannot_mix_error = || {
error!("cannot mix `cfg(...)` with deprecated syntax `names(...)` and `values(...)`")
};

let Ok(mut parser) = maybe_new_parser_from_source_str(&sess, filename, s.to_string())
else {
expected_error();
Expand All @@ -169,6 +173,8 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
if old_syntax == None {
check_cfg.exhaustive_names = false;
check_cfg.exhaustive_values = false;
} else if old_syntax == Some(false) {
cannot_mix_error();
}
old_syntax = Some(true);
};
Expand Down Expand Up @@ -226,6 +232,9 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
expected_error();
}
} else if meta_item.has_name(sym::cfg) {
if old_syntax == Some(true) {
cannot_mix_error();
}
old_syntax = Some(false);

let mut names = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
libc = { version = "0.2.149", default-features = false, features = ['rustc-dep-of-std'], public = true }
libc = { version = "0.2.150", default-features = false, features = ['rustc-dep-of-std'], public = true }
compiler_builtins = { version = "0.1.103" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ impl<'a> Builder<'a> {
}

// #[cfg(bootstrap)]
let use_new_check_cfg_syntax = self.local_rebuild;
let use_new_check_cfg_syntax = stage >= 1;

// Enable compile-time checking of `cfg` names, values and Cargo `features`.
//
Expand Down
52 changes: 26 additions & 26 deletions tests/ui/check-cfg/mix.cfg.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
warning: unexpected `cfg` condition name: `widnows`
--> $DIR/mix.rs:15:7
--> $DIR/mix.rs:16:7
|
LL | #[cfg(widnows)]
| ^^^^^^^ help: there is a config with a similar name: `windows`
|
= note: `#[warn(unexpected_cfgs)]` on by default

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

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

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

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

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

warning: unexpected `cfg` condition value: `bar`
--> $DIR/mix.rs:46:10
--> $DIR/mix.rs:47:10
|
LL | cfg!(feature = "bar");
| ^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:48:10
--> $DIR/mix.rs:49:10
|
LL | cfg!(feature = "zebra");
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

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

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:52:10
--> $DIR/mix.rs:53:10
|
LL | cfg!(xxx);
| ^^^

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:76:52
--> $DIR/mix.rs:77:52
|
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
Expand Down
Loading
Loading