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 Oct 11, 2024
1 parent d150663 commit aa8bb59
Show file tree
Hide file tree
Showing 2 changed files with 20 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
18 changes: 16 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,20 +640,36 @@ fn cfg_keywords() {
.with_stderr_data(str![[r#"
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(async)` is deprecated as `async` 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#async)`
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(fn)` is deprecated as `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!
|
| [HELP] use raw-idents instead: `cfg(r#fn)`
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(const)` is deprecated as `const` 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#const)`
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(return)` is deprecated as `return` 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#return)`
[WARNING] [.cargo/config.toml] future-incompatibility: `cfg(for)` is deprecated as `for` 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#for)`
[WARNING] [.cargo/config.toml] future-incompatibility: `cfg(match)` is deprecated as `match` 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#match)`
[WARNING] [.cargo/config.toml] future-incompatibility: `cfg(extern)` is deprecated as `extern` 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#extern)`
[WARNING] [.cargo/config.toml] future-incompatibility: `cfg(crate)` is deprecated as `crate` 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#crate)`
[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 aa8bb59

Please sign in to comment.