Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/conditional-compilation/cfg-arg-invalid-1.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions src/test/ui/conditional-compilation/cfg-arg-invalid-9.rs
Original file line number Diff line number Diff line change
@@ -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() {}
2 changes: 2 additions & 0 deletions src/test/ui/conditional-compilation/cfg-arg-invalid-9.stderr
Original file line number Diff line number Diff line change
@@ -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\")