From 7b3512f4d4f4cafceb2dfab58eb56639ec475e4c Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 11 Oct 2024 12:17:32 +0200 Subject: [PATCH] Adjust future-incompat cfg keyword with raw-idents in cfgs --- crates/cargo-platform/src/lib.rs | 6 ++++-- tests/testsuite/cfg.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/cargo-platform/src/lib.rs b/crates/cargo-platform/src/lib.rs index b3a2aa619d6..f0e8336003f 100644 --- a/crates/cargo-platform/src/lib.rs +++ b/crates/cargo-platform/src/lib.rs @@ -117,11 +117,13 @@ 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()) { 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() )); } diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index 1d8c6872cd7..054a02c4584 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -544,8 +544,6 @@ fn cfg_raw_idents() { p.cargo("check") .with_stderr_data(str![[r#" -[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(r#fn)` is deprecated as `r#fn` is a keyword and not an identifier and should not have have been accepted in this position. - | this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release! [LOCKING] 1 package to latest compatible version [CHECKING] foo v0.1.0 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s @@ -642,8 +640,12 @@ fn cfg_keywords() { .with_stderr_data(str![[r#" [WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(true)` is deprecated as `true` is a keyword and not an identifier and should not have have been accepted in this position. | this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release! + | + | [HELP] use raw-idents instead: `cfg(r#true)` [WARNING] [.cargo/config.toml] future-incompatibility: `cfg(false)` is deprecated as `false` is a keyword and not an identifier and should not have have been accepted in this position. | this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release! + | + | [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