Skip to content

Commit b0aefff

Browse files
committed
Auto merge of #32846 - jseyfried:allow_unconfigured_gated_expanded_items, r=nrc
Avoid gated feature checking unconfigured expanded items Avoid gated feature checking unconfigured macro-expanded items (fixes #32840). Unconfigured items that are not macro-expanded are already not gated feature checked. r? @nrc
2 parents 46504e9 + 86f069d commit b0aefff

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/librustc_driver/driver.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -645,21 +645,6 @@ pub fn phase_2_configure_and_expand(sess: &Session,
645645
ret
646646
});
647647

648-
// Needs to go *after* expansion to be able to check the results
649-
// of macro expansion. This runs before #[cfg] to try to catch as
650-
// much as possible (e.g. help the programmer avoid platform
651-
// specific differences)
652-
time(time_passes, "complete gated feature checking 1", || {
653-
sess.track_errors(|| {
654-
let features = syntax::feature_gate::check_crate(sess.codemap(),
655-
&sess.parse_sess.span_diagnostic,
656-
&krate,
657-
&attributes,
658-
sess.opts.unstable_features);
659-
*sess.features.borrow_mut() = features;
660-
})
661-
})?;
662-
663648
// JBC: make CFG processing part of expansion to avoid this problem:
664649

665650
// strip again, in case expansion added anything with a #[cfg].
@@ -698,10 +683,8 @@ pub fn phase_2_configure_and_expand(sess: &Session,
698683
"checking for inline asm in case the target doesn't support it",
699684
|| no_asm::check_crate(sess, &krate));
700685

701-
// One final feature gating of the true AST that gets compiled
702-
// later, to make sure we've got everything (e.g. configuration
703-
// can insert new attributes via `cfg_attr`)
704-
time(time_passes, "complete gated feature checking 2", || {
686+
// Needs to go *after* expansion to be able to check the results of macro expansion.
687+
time(time_passes, "complete gated feature checking", || {
705688
sess.track_errors(|| {
706689
let features = syntax::feature_gate::check_crate(sess.codemap(),
707690
&sess.parse_sess.span_diagnostic,

src/libsyntax/ext/expand.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ macro_rules! with_exts_frame {
327327
// When we enter a module, record it, for the sake of `module!`
328328
pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
329329
-> SmallVector<P<ast::Item>> {
330-
let it = expand_item_multi_modifier(Annotatable::Item(it), fld);
331-
332-
expand_annotatable(it, fld)
330+
expand_annotatable(Annotatable::Item(it), fld)
333331
.into_iter().map(|i| i.expect_item()).collect()
334332
}
335333

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

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs)]
12+
13+
macro_rules! mac {
14+
{} => {
15+
#[cfg(attr)]
16+
mod m {
17+
#[lang_item]
18+
fn f() {}
19+
}
20+
}
21+
}
22+
23+
mac! {}
24+
25+
#[rustc_error]
26+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)