diff options
| author | Kevin Ballard <kevin@sb.org> | 2015-05-14 00:54:05 -0700 |
|---|---|---|
| committer | Kevin Ballard <kevin@sb.org> | 2015-05-14 10:35:35 -0700 |
| commit | 90b952954bf7e765924f70a8892334b6bb7de93b (patch) | |
| tree | fac99302c259441fc506d91bd721ed20400f6fcc | |
| parent | 3ca008dcf12283247122f25928630f2a484ff768 (diff) | |
| download | rust-90b952954bf7e765924f70a8892334b6bb7de93b.tar.gz rust-90b952954bf7e765924f70a8892334b6bb7de93b.zip | |
Move configuration 1 phase before crate metadata collection
Stripping unconfigured items prior to collecting crate metadata means we can say things like `#![cfg_attr(foo, crate_type="lib")]`. Fixes #25347.
| -rw-r--r-- | src/librustc_driver/driver.rs | 22 | ||||
| -rw-r--r-- | src/test/auxiliary/crate-attributes-using-cfg_attr.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/crate-attributes-using-cfg_attr.rs | 15 |
3 files changed, 42 insertions, 11 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 0073c0b0610..9c78c5aec00 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -383,17 +383,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, -> Option<ast::Crate> { let time_passes = sess.time_passes(); - *sess.crate_types.borrow_mut() = - collect_crate_types(sess, &krate.attrs); - *sess.crate_metadata.borrow_mut() = - collect_crate_metadata(sess, &krate.attrs); - - time(time_passes, "recursion limit", (), |_| { - middle::recursion_limit::update_recursion_limit(sess, &krate); - }); - - // strip before expansion to allow macros to depend on - // configuration variables e.g/ in + // strip before anything else because crate metadata may use #[cfg_attr] + // and so macros can depend on configuration variables, such as // // #[macro_use] #[cfg(foo)] // mod bar { macro_rules! baz!(() => {{}}) } @@ -403,6 +394,15 @@ pub fn phase_2_configure_and_expand(sess: &Session, krate = time(time_passes, "configuration 1", krate, |krate| syntax::config::strip_unconfigured_items(sess.diagnostic(), krate)); + *sess.crate_types.borrow_mut() = + collect_crate_types(sess, &krate.attrs); + *sess.crate_metadata.borrow_mut() = + collect_crate_metadata(sess, &krate.attrs); + + time(time_passes, "recursion limit", (), |_| { + middle::recursion_limit::update_recursion_limit(sess, &krate); + }); + time(time_passes, "gated macro checking", (), |_| { let features = syntax::feature_gate::check_crate_macros(sess.codemap(), diff --git a/src/test/auxiliary/crate-attributes-using-cfg_attr.rs b/src/test/auxiliary/crate-attributes-using-cfg_attr.rs new file mode 100644 index 00000000000..0028b51f9d1 --- /dev/null +++ b/src/test/auxiliary/crate-attributes-using-cfg_attr.rs @@ -0,0 +1,16 @@ +// 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. + +// no-prefer-dynamic +// compile-flags: --cfg foo + +#![cfg_attr(foo, crate_type="lib")] + +pub fn foo() {} diff --git a/src/test/run-pass/crate-attributes-using-cfg_attr.rs b/src/test/run-pass/crate-attributes-using-cfg_attr.rs new file mode 100644 index 00000000000..72ccc6723f9 --- /dev/null +++ b/src/test/run-pass/crate-attributes-using-cfg_attr.rs @@ -0,0 +1,15 @@ +// 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. + +// aux-build:crate-attributes-using-cfg_attr.rs + +extern crate crate_attributes_using_cfg_attr; + +pub fn main() {} |
