From 0ea66f35a95e3662498881398298dcc553294d5a Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 8 Apr 2016 22:47:55 +0000 Subject: [PATCH 1/4] Avoid gated feature checking unconfigured items --- src/librustc_driver/driver.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 67c52bb6c36d7..b6e7080f16c7c 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -625,21 +625,6 @@ pub fn phase_2_configure_and_expand(sess: &Session, ret }); - // Needs to go *after* expansion to be able to check the results - // of macro expansion. This runs before #[cfg] to try to catch as - // much as possible (e.g. help the programmer avoid platform - // specific differences) - time(time_passes, "complete gated feature checking 1", || { - sess.track_errors(|| { - let features = syntax::feature_gate::check_crate(sess.codemap(), - &sess.parse_sess.span_diagnostic, - &krate, - &attributes, - sess.opts.unstable_features); - *sess.features.borrow_mut() = features; - }) - })?; - // JBC: make CFG processing part of expansion to avoid this problem: // strip again, in case expansion added anything with a #[cfg]. @@ -662,6 +647,19 @@ pub fn phase_2_configure_and_expand(sess: &Session, krate })?; + // Needs to go *after* expansion to be able to check the results + // of macro expansion. + time(time_passes, "complete gated feature checking 1", || { + sess.track_errors(|| { + let features = syntax::feature_gate::check_crate(sess.codemap(), + &sess.parse_sess.span_diagnostic, + &krate, + &attributes, + sess.opts.unstable_features); + *sess.features.borrow_mut() = features; + }) + })?; + krate = time(time_passes, "maybe building test harness", || { syntax::test::modify_for_testing(&sess.parse_sess, &sess.opts.cfg, krate, sess.diagnostic()) }); From 417a6df9b0764ff086d71fff9808a31715e9cd0d Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 8 Apr 2016 23:41:27 +0000 Subject: [PATCH 2/4] Add regression test --- src/test/compile-fail/expanded-cfg.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/compile-fail/expanded-cfg.rs diff --git a/src/test/compile-fail/expanded-cfg.rs b/src/test/compile-fail/expanded-cfg.rs new file mode 100644 index 0000000000000..2f74aeba9eb43 --- /dev/null +++ b/src/test/compile-fail/expanded-cfg.rs @@ -0,0 +1,26 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +macro_rules! mac { + {} => { + #[cfg(attr)] + mod m { + #[lang_item] + fn f() {} + } + } +} + +mac! {} + +#[rustc_error] +fn main() {} //~ ERROR compilation successful From 5eb775eedd64d3b3abab63a8ef39ca9664f4cad0 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 9 Apr 2016 00:16:57 +0000 Subject: [PATCH 3/4] Remove redundant gated feature checking pass --- src/librustc_driver/driver.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index b6e7080f16c7c..fa7ffec5a6acc 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -647,19 +647,6 @@ pub fn phase_2_configure_and_expand(sess: &Session, krate })?; - // Needs to go *after* expansion to be able to check the results - // of macro expansion. - time(time_passes, "complete gated feature checking 1", || { - sess.track_errors(|| { - let features = syntax::feature_gate::check_crate(sess.codemap(), - &sess.parse_sess.span_diagnostic, - &krate, - &attributes, - sess.opts.unstable_features); - *sess.features.borrow_mut() = features; - }) - })?; - krate = time(time_passes, "maybe building test harness", || { syntax::test::modify_for_testing(&sess.parse_sess, &sess.opts.cfg, krate, sess.diagnostic()) }); @@ -676,10 +663,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, "checking for inline asm in case the target doesn't support it", || no_asm::check_crate(sess, &krate)); - // One final feature gating of the true AST that gets compiled - // later, to make sure we've got everything (e.g. configuration - // can insert new attributes via `cfg_attr`) - time(time_passes, "complete gated feature checking 2", || { + // Needs to go *after* expansion to be able to check the results of macro expansion. + time(time_passes, "complete gated feature checking", || { sess.track_errors(|| { let features = syntax::feature_gate::check_crate(sess.codemap(), &sess.parse_sess.span_diagnostic, From 86f069d41a89122740d58d0eb8eaeb7496bb03ce Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 9 Apr 2016 05:37:31 +0000 Subject: [PATCH 4/4] Remove redundant call to `expand_item_multi_modifier` --- src/libsyntax/ext/expand.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 8550617560df3..27d7234aae216 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -309,9 +309,7 @@ macro_rules! with_exts_frame { // When we enter a module, record it, for the sake of `module!` pub fn expand_item(it: P, fld: &mut MacroExpander) -> SmallVector> { - let it = expand_item_multi_modifier(Annotatable::Item(it), fld); - - expand_annotatable(it, fld) + expand_annotatable(Annotatable::Item(it), fld) .into_iter().map(|i| i.expect_item()).collect() }