diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index c4a1272e6d04..eb50e4ef99f6 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -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 = 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); } } diff --git a/src/test/compile-fail/issue-31495.rs b/src/test/compile-fail/issue-31495.rs index 0a09b65700ab..794b8bb86bb5 100644 --- a/src/test/compile-fail/issue-31495.rs +++ b/src/test/compile-fail/issue-31495.rs @@ -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() {}