Skip to content

Commit

Permalink
Adjust future-incompat cfg keyword with raw-idents in cfgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Nov 2, 2024
1 parent df9abc6 commit ff762d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 7 additions & 3 deletions crates/cargo-platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,25 @@ impl Platform {
}
CfgExpr::Value(ref e) => match e {
Cfg::Name(name) | Cfg::KeyPair(name, _) => {
if KEYWORDS.contains(&name.as_str()) {
if !name.raw && KEYWORDS.contains(&name.as_str()) {
if name.as_str() == "true" || name.as_str() == "false" {
warnings.push(format!(
"[{}] future-incompatibility: the meaning of `cfg({e})` will change in the future\n \
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.\n \
| In the future these will be built-in defines that will have the corresponding true/false value.\n \
| It is recommended to avoid using these configs until they are properly supported.\n \
| See <https://github.com/rust-lang/rust/issues/131204> for more information.",
| See <https://github.com/rust-lang/rust/issues/131204> for more information.\n \
|\n \
| help: use raw-idents instead: `cfg(r#{name})`",
path.display()
));
} else {
warnings.push(format!(
"[{}] future-incompatibility: `cfg({e})` is deprecated as `{name}` is a keyword \
and not an identifier and should not have have been accepted in this position.\n \
| this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release!",
| this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release!\n \
|\n \
| help: use raw-idents instead: `cfg(r#{name})`",
path.display()
));
}
Expand Down
9 changes: 4 additions & 5 deletions tests/testsuite/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,6 @@ fn cfg_raw_idents() {

p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(r#true)` will change in the future
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
| In the future these will be built-in defines that will have the corresponding true/false value.
| It is recommended to avoid using these configs until they are properly supported.
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
[LOCKING] 1 package to latest compatible version
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down Expand Up @@ -648,11 +643,15 @@ fn cfg_keywords() {
| In the future these will be built-in defines that will have the corresponding true/false value.
| It is recommended to avoid using these configs until they are properly supported.
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
|
| [HELP] use raw-idents instead: `cfg(r#true)`
[WARNING] [.cargo/config.toml] future-incompatibility: the meaning of `cfg(false)` will change in the future
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
| In the future these will be built-in defines that will have the corresponding true/false value.
| It is recommended to avoid using these configs until they are properly supported.
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
|
| [HELP] use raw-idents instead: `cfg(r#false)`
[LOCKING] 1 package to latest compatible version
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down

0 comments on commit ff762d8

Please sign in to comment.