diff options
| author | Kamal Marhubi <kamal@marhubi.com> | 2016-02-08 18:47:03 -0500 |
|---|---|---|
| committer | Kamal Marhubi <kamal@marhubi.com> | 2016-02-08 18:47:03 -0500 |
| commit | c32c7c24860eb6ed65bdec2491ba99b6eb5550b8 (patch) | |
| tree | 61c875ac787a47196facdee14fe89408323b607c /src | |
| parent | 6d2c866e22ad1999d4a16b6b7345e031ef74655c (diff) | |
| download | rust-c32c7c24860eb6ed65bdec2491ba99b6eb5550b8.tar.gz rust-c32c7c24860eb6ed65bdec2491ba99b6eb5550b8.zip | |
driver: Include invalid predicate in error message
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_driver/lib.rs | 25 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-31495.rs | 2 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index c4a1272e6d0..eb50e4ef99f 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<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); } } diff --git a/src/test/compile-fail/issue-31495.rs b/src/test/compile-fail/issue-31495.rs index 0a09b65700a..794b8bb86bb 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() {} |
