Skip to content

Commit c32c7c2

Browse files
committed
driver: Include invalid predicate in error message
1 parent 6d2c866 commit c32c7c2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/librustc_driver/lib.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,30 @@ fn handle_explain(code: &str,
350350

351351
fn check_cfg(sopts: &config::Options,
352352
output: ErrorOutputType) {
353-
fn is_meta_list(item: &ast::MetaItem) -> bool {
353+
let mut emitter: Box<Emitter> = match output {
354+
config::ErrorOutputType::HumanReadable(color_config) => {
355+
Box::new(errors::emitter::BasicEmitter::stderr(color_config))
356+
}
357+
config::ErrorOutputType::Json => Box::new(errors::json::JsonEmitter::basic()),
358+
};
359+
360+
let mut saw_invalid_predicate = false;
361+
for item in sopts.cfg.iter() {
354362
match item.node {
355-
ast::MetaItem_::MetaList(..) => true,
356-
_ => false,
363+
ast::MetaList(ref pred, _) => {
364+
saw_invalid_predicate = true;
365+
emitter.emit(None,
366+
&format!("invalid predicate in --cfg command line argument: `{}`",
367+
pred),
368+
None,
369+
errors::Level::Fatal);
370+
}
371+
_ => {},
357372
}
358373
}
359374

360-
if sopts.cfg.iter().any(|item| is_meta_list(&*item)) {
361-
early_error(output, "predicates are not allowed in --cfg");
375+
if saw_invalid_predicate {
376+
panic!(errors::FatalError);
362377
}
363378
}
364379

src/test/compile-fail/issue-31495.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
// compile-flags: --cfg foo(bar)
12-
// error-pattern: predicates are not allowed in --cfg
12+
// error-pattern: invalid predicate in --cfg command line argument: `foo`
1313
fn main() {}

0 commit comments

Comments
 (0)