Rollup merge of #92835 - iwanders:issue-66450-improve-cfg-error-message, r=nagisa
Improve error message for key="value" cfg arguments. Hi, I ran into difficulties using the `--cfg` flag syntax, first hit when googling for the error was issue https://github.com/rust-lang/rust/issues/66450. Reading that issue, it sounded like the best way to improve the experience was to improve the error message, this is low risk and doesn't introduce any additional argument parsing. The issue mentions that it is entirely dependent on the shell, while this may be true, I think guiding the the user into the realization that the quotes may need to be escaped is helpful. The two suggested escapings both work in Bash and in the Windows command prompt. fyi `@ehuss`
This commit is contained in:
commit
e38cbc78aa
@ -124,7 +124,16 @@ macro_rules! error {
|
||||
Err(errs) => errs.into_iter().for_each(|mut err| err.cancel()),
|
||||
}
|
||||
|
||||
error!(r#"expected `key` or `key="value"`"#);
|
||||
// If the user tried to use a key="value" flag, but is missing the quotes, provide
|
||||
// a hint about how to resolve this.
|
||||
if s.contains("=") && !s.contains("=\"") && !s.ends_with("\"") {
|
||||
error!(concat!(
|
||||
r#"expected `key` or `key="value"`, ensure escaping is appropriate"#,
|
||||
r#" for your shell, try 'key="value"' or key=\"value\""#
|
||||
));
|
||||
} else {
|
||||
error!(r#"expected `key` or `key="value"`"#);
|
||||
}
|
||||
})
|
||||
.collect::<CrateConfig>();
|
||||
cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect()
|
||||
|
@ -1,3 +1,3 @@
|
||||
// compile-flags: --cfg a(b=c)
|
||||
// error-pattern: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`)
|
||||
// error-pattern: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
|
||||
fn main() {}
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`)
|
||||
error: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
|
||||
|
||||
|
4
src/test/ui/conditional-compilation/cfg-arg-invalid-9.rs
Normal file
4
src/test/ui/conditional-compilation/cfg-arg-invalid-9.rs
Normal file
@ -0,0 +1,4 @@
|
||||
// Test for missing quotes around value, issue #66450.
|
||||
// compile-flags: --cfg key=value
|
||||
// error-pattern: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
|
||||
fn main() {}
|
@ -0,0 +1,2 @@
|
||||
error: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
|
||||
|
Loading…
Reference in New Issue
Block a user