diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-04 14:59:42 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-07 12:04:28 -0800 |
| commit | 3dbd32854f6bdee94c98c5e3e5da58fb79d79fd9 (patch) | |
| tree | c38be4cf6f5ffdf89a3983635849a90b502d87fb /src/test | |
| parent | 45cbdec4174778bf915f17561ef971c068a7fcbc (diff) | |
| download | rust-3dbd32854f6bdee94c98c5e3e5da58fb79d79fd9.tar.gz rust-3dbd32854f6bdee94c98c5e3e5da58fb79d79fd9.zip | |
rustc: Process #[cfg]/#[cfg_attr] on crates
This commit implements processing these two attributes at the crate level as well as at the item level. When #[cfg] is applied at the crate level, then the entire crate will be omitted if the cfg doesn't match. The #[cfg_attr] attribute is processed as usual in that the attribute is included or not depending on whether the cfg matches. This was spurred on by motivations of #18585 where #[cfg_attr] annotations will be applied at the crate-level. cc #18585
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/auxiliary/stability_cfg1.rs | 12 | ||||
| -rw-r--r-- | src/test/auxiliary/stability_cfg2.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/cfg-in-crate-1.rs | 13 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-stability.rs | 5 | ||||
| -rw-r--r-- | src/test/run-make/graphviz-flowgraph/f03.dot-expected.dot | 8 | ||||
| -rw-r--r-- | src/test/run-make/graphviz-flowgraph/f03.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/cfg-in-crate-1.rs | 16 |
7 files changed, 66 insertions, 5 deletions
diff --git a/src/test/auxiliary/stability_cfg1.rs b/src/test/auxiliary/stability_cfg1.rs new file mode 100644 index 00000000000..6b2e8e7758f --- /dev/null +++ b/src/test/auxiliary/stability_cfg1.rs @@ -0,0 +1,12 @@ +// Copyright 2014 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. + +#![cfg_attr(foo, experimental)] +#![cfg_attr(not(foo), stable)] diff --git a/src/test/auxiliary/stability_cfg2.rs b/src/test/auxiliary/stability_cfg2.rs new file mode 100644 index 00000000000..3387b319abf --- /dev/null +++ b/src/test/auxiliary/stability_cfg2.rs @@ -0,0 +1,15 @@ +// Copyright 2014 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 + +#![cfg_attr(foo, experimental)] +#![cfg_attr(not(foo), stable)] + diff --git a/src/test/compile-fail/cfg-in-crate-1.rs b/src/test/compile-fail/cfg-in-crate-1.rs new file mode 100644 index 00000000000..94ae8d89b4f --- /dev/null +++ b/src/test/compile-fail/cfg-in-crate-1.rs @@ -0,0 +1,13 @@ +// Copyright 2014 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. + +// error-pattern:main function not found + +#![cfg(bar)] diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 2074d007502..483a3b6d667 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -10,6 +10,8 @@ // aux-build:lint_stability.rs // aux-build:inherited_stability.rs +// aux-build:stability_cfg1.rs +// aux-build:stability_cfg2.rs #![feature(globs, phase)] #![deny(unstable)] @@ -18,6 +20,9 @@ #![allow(dead_code)] mod cross_crate { + extern crate stability_cfg1; + extern crate stability_cfg2; //~ ERROR: use of experimental item + #[phase(plugin, link)] extern crate lint_stability; //~ ERROR: use of unmarked item use self::lint_stability::*; diff --git a/src/test/run-make/graphviz-flowgraph/f03.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f03.dot-expected.dot index e60d349ad14..1986c27ad43 100644 --- a/src/test/run-make/graphviz-flowgraph/f03.dot-expected.dot +++ b/src/test/run-make/graphviz-flowgraph/f03.dot-expected.dot @@ -2,10 +2,10 @@ digraph block { N0[label="entry"]; N1[label="exit"]; N2[label="expr 3i"]; - N3[label="expr 33i"]; - N4[label="expr 3i + 33i"]; - N5[label="stmt 3i + 33i;"]; - N6[label="block { 3i + 33i; }"]; + N3[label="expr 4"]; + N4[label="expr 3i + 4"]; + N5[label="stmt 3i + 4;"]; + N6[label="block { 3i + 4; }"]; N0 -> N2; N2 -> N3; N3 -> N4; diff --git a/src/test/run-make/graphviz-flowgraph/f03.rs b/src/test/run-make/graphviz-flowgraph/f03.rs index 1007225f2f2..051409a49b1 100644 --- a/src/test/run-make/graphviz-flowgraph/f03.rs +++ b/src/test/run-make/graphviz-flowgraph/f03.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn expr_add_3() { - 3i + 33i; + 3i + 4; } diff --git a/src/test/run-pass/cfg-in-crate-1.rs b/src/test/run-pass/cfg-in-crate-1.rs new file mode 100644 index 00000000000..06f679b7fca --- /dev/null +++ b/src/test/run-pass/cfg-in-crate-1.rs @@ -0,0 +1,16 @@ +// Copyright 2014 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 bar -D warnings +// ignore-pretty + +#![cfg(bar)] + +fn main() {} |
