Skip to content

Commit

Permalink
driver: Disallow predicates in --cfg specs
Browse files Browse the repository at this point in the history
A spec like `#[cfg(foo(bar))]` is not allowed as an attribute. This
makes the same spec be rejected by the compiler if passed in as a
`--cfg` argument.

Fixes rust-lang#31495
  • Loading branch information
kamalmarhubi committed Feb 8, 2016
1 parent 4c4bb5f commit 6d2c866
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,24 @@ fn handle_explain(code: &str,
}
}

fn check_cfg(sopts: &config::Options,
output: ErrorOutputType) {
fn is_meta_list(item: &ast::MetaItem) -> bool {
match item.node {
ast::MetaItem_::MetaList(..) => true,
_ => false,
}
}

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

impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
fn early_callback(&mut self,
matches: &getopts::Matches,
_sopts: &config::Options,
sopts: &config::Options,
descriptions: &diagnostics::registry::Registry,
output: ErrorOutputType)
-> Compilation {
Expand All @@ -360,6 +374,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
return Compilation::Stop;
}

check_cfg(sopts, output);
Compilation::Continue
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/compile-fail/issue-31495.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2015 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 foo(bar)
// error-pattern: predicates are not allowed in --cfg
fn main() {}

0 comments on commit 6d2c866

Please sign in to comment.