Skip to content

Commit

Permalink
driver: Include invalid predicate in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalmarhubi committed Feb 8, 2016
1 parent 6d2c866 commit c32c7c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,30 @@ fn handle_explain(code: &str,

fn check_cfg(sopts: &config::Options,
output: ErrorOutputType) {
fn is_meta_list(item: &ast::MetaItem) -> bool {
let mut emitter: Box<Emitter> = match output {
config::ErrorOutputType::HumanReadable(color_config) => {
Box::new(errors::emitter::BasicEmitter::stderr(color_config))
}
config::ErrorOutputType::Json => Box::new(errors::json::JsonEmitter::basic()),
};

let mut saw_invalid_predicate = false;
for item in sopts.cfg.iter() {
match item.node {
ast::MetaItem_::MetaList(..) => true,
_ => false,
ast::MetaList(ref pred, _) => {
saw_invalid_predicate = true;
emitter.emit(None,
&format!("invalid predicate in --cfg command line argument: `{}`",
pred),
None,
errors::Level::Fatal);
}
_ => {},
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-31495.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// except according to those terms.

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

0 comments on commit c32c7c2

Please sign in to comment.