diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-21 22:03:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-21 22:03:14 +0100 |
| commit | e38cbc78aa18354a8b4e1477cd090bd83c298ced (patch) | |
| tree | e7af78ff9601cdcba2bd921c36afe4ee4f7a1f7c /compiler/rustc_interface/src | |
| parent | 701a8330e8ee2135137fa3fed5154e5d03945df9 (diff) | |
| parent | af87248037a8c86f580c469ce7d2a10c0b12f2fd (diff) | |
| download | rust-e38cbc78aa18354a8b4e1477cd090bd83c298ced.tar.gz rust-e38cbc78aa18354a8b4e1477cd090bd83c298ced.zip | |
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`
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 3804e100307..26343561959 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -124,7 +124,16 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String 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() |
