mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Fix quote escaping inside check-cfg value
This commit is contained in:
parent
bc8e034c39
commit
ccd3e99a1a
@ -48,10 +48,9 @@ enum EscapeQuotes {
|
||||
|
||||
fn to_check_cfg_arg(name: Symbol, value: Option<Symbol>, quotes: EscapeQuotes) -> String {
|
||||
if let Some(value) = value {
|
||||
let value = str::escape_debug(value.as_str()).to_string();
|
||||
let values = match quotes {
|
||||
EscapeQuotes::Yes => {
|
||||
format!("\\\"{}\\\"", str::escape_debug(value.as_str()).to_string())
|
||||
}
|
||||
EscapeQuotes::Yes => format!("\\\"{}\\\"", value.replace("\"", "\\\\\\\\\"")),
|
||||
EscapeQuotes::No => format!("\"{value}\""),
|
||||
};
|
||||
format!("cfg({name}, values({values}))")
|
||||
|
@ -1,5 +1,5 @@
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:8:7
|
||||
--> $DIR/diagnotics.rs:9:7
|
||||
|
|
||||
LL | #[cfg(featur)]
|
||||
| ^^^^^^ help: there is a config with a similar name: `feature`
|
||||
@ -9,7 +9,7 @@ LL | #[cfg(featur)]
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:12:7
|
||||
--> $DIR/diagnotics.rs:13:7
|
||||
|
|
||||
LL | #[cfg(featur = "foo")]
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -21,7 +21,7 @@ LL | #[cfg(feature = "foo")]
|
||||
| ~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:16:7
|
||||
--> $DIR/diagnotics.rs:17:7
|
||||
|
|
||||
LL | #[cfg(featur = "fo")]
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -34,7 +34,7 @@ LL | #[cfg(feature = "foo")]
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition name: `no_value`
|
||||
--> $DIR/diagnotics.rs:23:7
|
||||
--> $DIR/diagnotics.rs:24:7
|
||||
|
|
||||
LL | #[cfg(no_value)]
|
||||
| ^^^^^^^^ help: there is a config with a similar name: `no_values`
|
||||
@ -47,7 +47,7 @@ LL | #[cfg(no_value)]
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
|
||||
|
||||
warning: unexpected `cfg` condition name: `no_value`
|
||||
--> $DIR/diagnotics.rs:27:7
|
||||
--> $DIR/diagnotics.rs:28:7
|
||||
|
|
||||
LL | #[cfg(no_value = "foo")]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@ -64,7 +64,7 @@ LL | #[cfg(no_values)]
|
||||
| ~~~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition value: `bar`
|
||||
--> $DIR/diagnotics.rs:31:7
|
||||
--> $DIR/diagnotics.rs:32:7
|
||||
|
|
||||
LL | #[cfg(no_values = "bar")]
|
||||
| ^^^^^^^^^--------
|
||||
@ -79,5 +79,21 @@ LL | #[cfg(no_values = "bar")]
|
||||
= help: or consider adding `println!("cargo::rustc-check-cfg=cfg(no_values, values(\"bar\"))");` to the top of the `build.rs`
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
|
||||
|
||||
warning: 6 warnings emitted
|
||||
warning: unexpected `cfg` condition value: `quote"`
|
||||
--> $DIR/diagnotics.rs:36:7
|
||||
|
|
||||
LL | #[cfg(quote = "quote\"")]
|
||||
| ^^^^^^^^---------
|
||||
| |
|
||||
| help: there is a expected value with a similar name: `"quote"`
|
||||
|
|
||||
= note: expected values for `quote` are: `quote`
|
||||
= help: consider using a Cargo feature instead
|
||||
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(quote, values("quote\""))'] }
|
||||
= help: or consider adding `println!("cargo::rustc-check-cfg=cfg(quote, values(\"quote\\\"\"))");` to the top of the `build.rs`
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
|
||||
|
||||
warning: 7 warnings emitted
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
//@ [rustc]unset-rustc-env:CARGO_CRATE_NAME
|
||||
//@ [cargo]rustc-env:CARGO_CRATE_NAME=foo
|
||||
//@ compile-flags: --check-cfg=cfg(feature,values("foo")) --check-cfg=cfg(no_values)
|
||||
//@ compile-flags: --check-cfg=cfg(quote,values("quote"))
|
||||
|
||||
#[cfg(featur)]
|
||||
//~^ WARNING unexpected `cfg` condition name
|
||||
@ -32,4 +33,8 @@ fn no_values() {}
|
||||
//~^ WARNING unexpected `cfg` condition value
|
||||
fn no_values() {}
|
||||
|
||||
#[cfg(quote = "quote\"")]
|
||||
//~^ WARNING unexpected `cfg` condition value
|
||||
fn no_values() {}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:8:7
|
||||
--> $DIR/diagnotics.rs:9:7
|
||||
|
|
||||
LL | #[cfg(featur)]
|
||||
| ^^^^^^ help: there is a config with a similar name: `feature`
|
||||
@ -10,7 +10,7 @@ LL | #[cfg(featur)]
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:12:7
|
||||
--> $DIR/diagnotics.rs:13:7
|
||||
|
|
||||
LL | #[cfg(featur = "foo")]
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -23,7 +23,7 @@ LL | #[cfg(feature = "foo")]
|
||||
| ~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition name: `featur`
|
||||
--> $DIR/diagnotics.rs:16:7
|
||||
--> $DIR/diagnotics.rs:17:7
|
||||
|
|
||||
LL | #[cfg(featur = "fo")]
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -37,7 +37,7 @@ LL | #[cfg(feature = "foo")]
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition name: `no_value`
|
||||
--> $DIR/diagnotics.rs:23:7
|
||||
--> $DIR/diagnotics.rs:24:7
|
||||
|
|
||||
LL | #[cfg(no_value)]
|
||||
| ^^^^^^^^ help: there is a config with a similar name: `no_values`
|
||||
@ -46,7 +46,7 @@ LL | #[cfg(no_value)]
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
|
||||
|
||||
warning: unexpected `cfg` condition name: `no_value`
|
||||
--> $DIR/diagnotics.rs:27:7
|
||||
--> $DIR/diagnotics.rs:28:7
|
||||
|
|
||||
LL | #[cfg(no_value = "foo")]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@ -59,7 +59,7 @@ LL | #[cfg(no_values)]
|
||||
| ~~~~~~~~~
|
||||
|
||||
warning: unexpected `cfg` condition value: `bar`
|
||||
--> $DIR/diagnotics.rs:31:7
|
||||
--> $DIR/diagnotics.rs:32:7
|
||||
|
|
||||
LL | #[cfg(no_values = "bar")]
|
||||
| ^^^^^^^^^--------
|
||||
@ -70,5 +70,17 @@ LL | #[cfg(no_values = "bar")]
|
||||
= help: to expect this configuration use `--check-cfg=cfg(no_values, values("bar"))`
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
|
||||
|
||||
warning: 6 warnings emitted
|
||||
warning: unexpected `cfg` condition value: `quote"`
|
||||
--> $DIR/diagnotics.rs:36:7
|
||||
|
|
||||
LL | #[cfg(quote = "quote\"")]
|
||||
| ^^^^^^^^---------
|
||||
| |
|
||||
| help: there is a expected value with a similar name: `"quote"`
|
||||
|
|
||||
= note: expected values for `quote` are: `quote`
|
||||
= help: to expect this configuration use `--check-cfg=cfg(quote, values("quote\""))`
|
||||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
|
||||
|
||||
warning: 7 warnings emitted
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user