about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-15 19:30:37 +0000
committerbors <bors@rust-lang.org>2016-02-15 19:30:37 +0000
commit17d284b4b5af8aa2d58c3bf05b937d5b9d1adeb0 (patch)
treec6a5e40122f2dbf0f816e6821c4abe319d33532b /src
parent7a737d56e93b27fbeabae554168f454cdbb94842 (diff)
parent2766e254b1c326fb32414496c9532bcb3d3f1d51 (diff)
Auto merge of #31530 - dirk:dirk/restrict-matching-of-cfg-opts, r=alexcrichton
Fixes #31497.
Diffstat (limited to 'src')
-rw-r--r--src/error_index_generator/main.rs (renamed from src/error-index-generator/main.rs)0
-rw-r--r--src/librustc/session/config.rs18
-rw-r--r--src/test/compile-fail/cfg-arg-invalid.rs13
3 files changed, 27 insertions, 4 deletions
diff --git a/src/error-index-generator/main.rs b/src/error_index_generator/main.rs
index db9dd006f3c..db9dd006f3c 100644
--- a/src/error-index-generator/main.rs
+++ b/src/error_index_generator/main.rs
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index c96713a7285..28422989ea1 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -28,6 +28,7 @@ use syntax::attr;
 use syntax::attr::AttrMetaMethods;
 use syntax::errors::{ColorConfig, Handler};
 use syntax::parse;
+use syntax::parse::lexer::Reader;
 use syntax::parse::token::InternedString;
 use syntax::feature_gate::UnstableFeatures;
 
@@ -906,10 +907,19 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
 // Convert strings provided as --cfg [cfgspec] into a crate_cfg
 pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
     cfgspecs.into_iter().map(|s| {
-        parse::parse_meta_from_source_str("cfgspec".to_string(),
-                                          s.to_string(),
-                                          Vec::new(),
-                                          &parse::ParseSess::new())
+        let sess = parse::ParseSess::new();
+        let mut parser = parse::new_parser_from_source_str(&sess,
+                                                           Vec::new(),
+                                                           "cfgspec".to_string(),
+                                                           s.to_string());
+        let meta_item = panictry!(parser.parse_meta_item());
+
+        if !parser.reader.is_eof() {
+            early_error(ErrorOutputType::default(), &format!("invalid --cfg argument: {}",
+                                                             s))
+        }
+
+        meta_item
     }).collect::<ast::CrateConfig>()
 }
 
diff --git a/src/test/compile-fail/cfg-arg-invalid.rs b/src/test/compile-fail/cfg-arg-invalid.rs
new file mode 100644
index 00000000000..404630399c6
--- /dev/null
+++ b/src/test/compile-fail/cfg-arg-invalid.rs
@@ -0,0 +1,13 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: --cfg a{b}
+// error-pattern: invalid --cfg argument: a{b}
+fn main() {}