mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Add support for boolean literals in target cfgs
This commit is contained in:
parent
9a7a8cfb3b
commit
9563738dff
@ -11,6 +11,8 @@ pub enum CfgExpr {
|
||||
All(Vec<CfgExpr>),
|
||||
Any(Vec<CfgExpr>),
|
||||
Value(Cfg),
|
||||
True,
|
||||
False,
|
||||
}
|
||||
|
||||
/// A cfg value.
|
||||
@ -147,6 +149,8 @@ impl CfgExpr {
|
||||
CfgExpr::All(ref e) => e.iter().all(|e| e.matches(cfg)),
|
||||
CfgExpr::Any(ref e) => e.iter().any(|e| e.matches(cfg)),
|
||||
CfgExpr::Value(ref e) => cfg.contains(e),
|
||||
CfgExpr::True => true,
|
||||
CfgExpr::False => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,6 +178,8 @@ impl fmt::Display for CfgExpr {
|
||||
CfgExpr::All(ref e) => write!(f, "all({})", CommaSep(e)),
|
||||
CfgExpr::Any(ref e) => write!(f, "any({})", CommaSep(e)),
|
||||
CfgExpr::Value(ref e) => write!(f, "{}", e),
|
||||
CfgExpr::True => write!(f, "true"),
|
||||
CfgExpr::False => write!(f, "false"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,7 +235,11 @@ impl<'a> Parser<'a> {
|
||||
self.eat(&Token::RightParen)?;
|
||||
Ok(CfgExpr::Not(Box::new(e)))
|
||||
}
|
||||
Some(Ok(..)) => self.cfg().map(CfgExpr::Value),
|
||||
Some(Ok(..)) => self.cfg().map(|v| match v {
|
||||
Cfg::Name(n) if n == "true" => CfgExpr::True,
|
||||
Cfg::Name(n) if n == "false" => CfgExpr::False,
|
||||
v => CfgExpr::Value(v),
|
||||
}),
|
||||
Some(Err(..)) => Err(self.t.next().unwrap().err().unwrap()),
|
||||
None => Err(ParseError::new(
|
||||
self.t.orig,
|
||||
|
@ -98,6 +98,7 @@ impl Platform {
|
||||
))
|
||||
},
|
||||
}
|
||||
CfgExpr::True | CfgExpr::False => {},
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,30 +116,18 @@ impl Platform {
|
||||
check_cfg_expr(e, warnings, path);
|
||||
}
|
||||
}
|
||||
CfgExpr::True | CfgExpr::False => {}
|
||||
CfgExpr::Value(ref e) => match e {
|
||||
Cfg::Name(name) | Cfg::KeyPair(name, _) => {
|
||||
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.\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!\n \
|
||||
|\n \
|
||||
| help: use raw-idents instead: `cfg(r#{name})`",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
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!\n \
|
||||
|\n \
|
||||
| help: use raw-idents instead: `cfg(r#{name})`",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -39,6 +39,8 @@ macro_rules! e {
|
||||
(any($($t:tt),*)) => (CfgExpr::Any(vec![$(e!($t)),*]));
|
||||
(all($($t:tt),*)) => (CfgExpr::All(vec![$(e!($t)),*]));
|
||||
(not($($t:tt)*)) => (CfgExpr::Not(Box::new(e!($($t)*))));
|
||||
(true) => (CfgExpr::True);
|
||||
(false) => (CfgExpr::False);
|
||||
(($($t:tt)*)) => (e!($($t)*));
|
||||
($($t:tt)*) => (CfgExpr::Value(c!($($t)*)));
|
||||
}
|
||||
@ -122,6 +124,9 @@ fn cfg_expr() {
|
||||
good(" foo=\"3\" ", e!(foo = "3"));
|
||||
good("foo = \"3 e\"", e!(foo = "3 e"));
|
||||
|
||||
good("true", e!(true));
|
||||
good("false", e!(false));
|
||||
|
||||
good("all()", e!(all()));
|
||||
good("all(a)", e!(all(a)));
|
||||
good("all(a, b)", e!(all(a, b)));
|
||||
@ -249,6 +254,8 @@ fn check_cfg_attributes() {
|
||||
ok("windows");
|
||||
ok("any(not(unix), windows)");
|
||||
ok("foo");
|
||||
ok("true");
|
||||
ok("false");
|
||||
|
||||
ok("target_arch = \"abc\"");
|
||||
ok("target_feature = \"abc\"");
|
||||
|
@ -545,6 +545,7 @@ fn cfg_raw_idents() {
|
||||
p.cargo("check")
|
||||
.with_stderr_data(str![[r#"
|
||||
[LOCKING] 1 package to latest compatible version
|
||||
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] foo v0.1.0 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
@ -638,21 +639,8 @@ fn cfg_keywords() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [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] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] foo v0.1.0 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
@ -687,23 +675,9 @@ fn cfg_booleans() {
|
||||
.build();
|
||||
|
||||
p.cargo("check")
|
||||
// FIXME: `b` should be compiled
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [[ROOT]/foo/Cargo.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)`
|
||||
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [HELP] use raw-idents instead: `cfg(r#true)`
|
||||
[LOCKING] 2 packages to latest compatible versions
|
||||
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] a v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
@ -735,13 +709,6 @@ fn cfg_booleans_config() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [.cargo/config.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [HELP] use raw-idents instead: `cfg(r#true)`
|
||||
[CHECKING] a v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
@ -772,13 +739,6 @@ fn cfg_booleans_not() {
|
||||
|
||||
p.cargo("check")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [[ROOT]/foo/Cargo.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] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] a v0.0.1 ([ROOT]/foo)
|
||||
@ -810,30 +770,9 @@ fn cfg_booleans_combinators() {
|
||||
.build();
|
||||
|
||||
p.cargo("check")
|
||||
// FIXME: `b` should be compiled
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [HELP] use raw-idents instead: `cfg(r#true)`
|
||||
[WARNING] [[ROOT]/foo/Cargo.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)`
|
||||
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [HELP] use raw-idents instead: `cfg(r#true)`
|
||||
[LOCKING] 1 package to latest compatible version
|
||||
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] a v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
@ -868,26 +807,10 @@ fn cfg_booleans_rustflags_no_effect() {
|
||||
.build();
|
||||
|
||||
p.cargo("check")
|
||||
// FIXME: only `b` should be compiled, the rustflags don't take effect
|
||||
.env("RUSTFLAGS", "--cfg false")
|
||||
.with_stderr_data(str![[r#"
|
||||
[WARNING] [[ROOT]/foo/Cargo.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)`
|
||||
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(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.
|
||||
|
|
||||
| [HELP] use raw-idents instead: `cfg(r#true)`
|
||||
[LOCKING] 2 packages to latest compatible versions
|
||||
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
|
||||
[CHECKING] c v0.0.1 ([ROOT]/foo/c)
|
||||
[CHECKING] a v0.0.1 ([ROOT]/foo)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user