From 90330b5330954d0e60b44c934e14f6323a759e1d Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Wed, 12 Jan 2022 19:04:16 -0500 Subject: Improve error message for cfg arguments. This provides the user with a helpful error message in case a key="value" message was specified but couldn't be parsed. --- compiler/rustc_interface/src/interface.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_interface/src/interface.rs') diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 3804e100307..8fa1e18df3c 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -124,7 +124,10 @@ pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option errs.into_iter().for_each(|mut err| err.cancel()), } - error!(r#"expected `key` or `key="value"`"#); + error!(concat!( + r#"expected `key` or `key="value"`, ensure escaping is appropriate"#, + r#" for your shell, try 'key="value"' or key=\"value\""# + )); }) .collect::(); cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect() -- cgit 1.4.1-3-g733a5 From 1531d26fa3896869818b40d6771d8b3cdaf2f6eb Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sun, 16 Jan 2022 11:43:16 -0500 Subject: Limit scope of the hint about escaping. --- compiler/rustc_interface/src/interface.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_interface/src/interface.rs') diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 8fa1e18df3c..26343561959 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -124,10 +124,16 @@ pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option errs.into_iter().for_each(|mut err| err.cancel()), } - error!(concat!( - r#"expected `key` or `key="value"`, ensure escaping is appropriate"#, - r#" for your shell, try 'key="value"' 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::(); cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect() -- cgit 1.4.1-3-g733a5