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
This commit is contained in:
parent
45cbdec417
commit
3dbd32854f
11 changed files with 127 additions and 23 deletions
12
src/test/auxiliary/stability_cfg1.rs
Normal file
12
src/test/auxiliary/stability_cfg1.rs
Normal file
|
|
@ -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)]
|
||||
15
src/test/auxiliary/stability_cfg2.rs
Normal file
15
src/test/auxiliary/stability_cfg2.rs
Normal file
|
|
@ -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)]
|
||||
|
||||
13
src/test/compile-fail/cfg-in-crate-1.rs
Normal file
13
src/test/compile-fail/cfg-in-crate-1.rs
Normal file
|
|
@ -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)]
|
||||
|
|
@ -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::*;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@
|
|||
// except according to those terms.
|
||||
|
||||
pub fn expr_add_3() {
|
||||
3i + 33i;
|
||||
3i + 4;
|
||||
}
|
||||
|
|
|
|||
16
src/test/run-pass/cfg-in-crate-1.rs
Normal file
16
src/test/run-pass/cfg-in-crate-1.rs
Normal file
|
|
@ -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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue