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 1, 2024
1 parent 8873ed2 commit 7b3512f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions crates/cargo-platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));
}
Expand Down
6 changes: 4 additions & 2 deletions tests/testsuite/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b3512f

Please sign in to comment.