Skip to content

Commit 4cb9ca9

Browse files
committed
auto merge of #5410 : luqmana/rust/cfg-and, r=graydon
This adopts the syntax from #2119. No more annoying workarounds involving wrapping in mods!
2 parents 251d0c4 + 811d880 commit 4cb9ca9

File tree

4 files changed

+65
-14
lines changed

4 files changed

+65
-14
lines changed

src/compiletest/runtest.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,19 @@ actual:\n\
208208
testfile: &Path, src: ~str) -> ProcRes {
209209
compose_and_run_compiler(
210210
config, props, testfile,
211-
make_typecheck_args(config, testfile),
211+
make_typecheck_args(config, props, testfile),
212212
Some(src))
213213
}
214214

215-
fn make_typecheck_args(config: config, testfile: &Path) -> ProcArgs {
215+
fn make_typecheck_args(config: config, props: TestProps, testfile: &Path) -> ProcArgs {
216216
let prog = config.rustc_path;
217217
let mut args = ~[~"-",
218218
~"--no-trans", ~"--lib",
219219
~"-L", config.build_base.to_str(),
220220
~"-L",
221221
aux_output_dir_name(config, testfile).to_str()];
222222
args += split_maybe_args(config.rustcflags);
223+
args += split_maybe_args(props.compile_flags);
223224
return ProcArgs {prog: prog.to_str(), args: args};
224225
}
225226
}

src/librustc/front/config.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,19 @@ pub fn metas_in_cfg(cfg: ast::crate_cfg,
185185
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
186186
// so we can match against them. This is the list of configurations for
187187
// which the item is valid
188-
let cfg_metas =
189-
vec::concat(
190-
vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i)));
191-
192-
let has_cfg_metas = vec::len(cfg_metas) > 0u;
193-
if !has_cfg_metas { return true; }
194-
195-
for cfg_metas.each |cfg_mi| {
196-
if attr::contains(cfg, *cfg_mi) { return true; }
197-
}
198-
199-
return false;
188+
let cfg_metas = vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i));
189+
190+
if cfg_metas.all(|c| c.is_empty()) { return true; }
191+
192+
cfg_metas.any(|cfg_meta| {
193+
cfg_meta.all(|cfg_mi| {
194+
match cfg_mi.node {
195+
ast::meta_list(s, ref it) if *s == ~"not"
196+
=> it.all(|mi| !attr::contains(cfg, *mi)),
197+
_ => attr::contains(cfg, *cfg_mi)
198+
}
199+
})
200+
})
200201
}
201202

202203

src/test/compile-fail/test-cfg.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --cfg foo
12+
13+
#[cfg(foo, bar)] // foo AND bar
14+
fn foo() {}
15+
16+
fn main() {
17+
foo(); //~ ERROR unresolved name: `foo`.
18+
}

src/test/run-pass/cfgs-on-items.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
// compile-flags: --cfg fooA --cfg fooB
13+
14+
// fooA AND !bar
15+
#[cfg(fooA, not(bar))]
16+
fn foo1() -> int { 1 }
17+
18+
// !fooA AND !bar
19+
#[cfg(not(fooA, bar))]
20+
fn foo2() -> int { 2 }
21+
22+
// fooC OR (fooB AND !bar)
23+
#[cfg(fooC)]
24+
#[cfg(fooB, not(bar))]
25+
fn foo2() -> int { 3 }
26+
27+
28+
fn main() {
29+
fail_unless!(1 == foo1());
30+
fail_unless!(3 == foo2());
31+
}

0 commit comments

Comments
 (0)