Auto merge of #32791 - LeoTestard:feature-gate-clean, r=nikomatsakis
Feature gate clean This PR does a bit of cleaning in the feature-gate-handling code of libsyntax. It also fixes two bugs (#32782 and #32648). Changes include: * Change the way the existing features are declared in `feature_gate.rs`. The array of features and the `Features` struct are now defined together by a single macro. `featureck.py` has been updated accordingly. Note: there are now three different arrays for active, removed and accepted features instead of a single one with a `Status` item to tell wether a feature is active, removed, or accepted. This is mainly due to the way I implemented my macro in the first time and I can switch back to a single array if needed. But an advantage of the way it is now is that when an active feature is used, the parser only searches through the list of active features. It goes through the other arrays only if the feature is not found. I like to think that error checking (in this case, checking that an used feature is active) does not slow down compilation of valid code. :) But this is not very important... * Feature-gate checking pass now use the `Features` structure instead of looking through a string vector. This should speed them up a bit. The construction of the `Features` struct should be faster too since it is build directly when parsing features instead of calling `has_feature` dozens of times. * The MacroVisitor pass has been removed, it was mostly useless since the `#[cfg]-stripping` phase happens before (fixes #32648). The features that must actually be checked before expansion are now checked at the time they are used. This also allows us to check attributes that are generated by macro expansion and not visible to MacroVisitor, but are also removed by macro expansion and thus not visible to PostExpansionVisitor either. This fixes #32782. Note that in order for `#[derive_*]` to be feature-gated but still accepted when generated by `#[derive(Trait)]`, I had to do a little bit of trickery with spans that I'm not totally confident into. Please review that part carefully. (It's in `libsyntax_ext/deriving/mod.rs`.):: Note: this is a [breaking change], since programs with feature-gated attributes on macro-generated macro invocations were not rejected before. For example: ```rust macro_rules! bar ( () => () ); macro_rules! foo ( () => ( #[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps bar!(); ); ); ``` foo!();
This commit is contained in:
commit
435095f32a
12 changed files with 626 additions and 677 deletions
|
|
@ -11,8 +11,8 @@
|
|||
macro_rules! bar {
|
||||
() => {
|
||||
// more layers don't help:
|
||||
#[allow_internal_unstable]
|
||||
macro_rules! baz { //~ ERROR allow_internal_unstable side-steps
|
||||
#[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps
|
||||
macro_rules! baz {
|
||||
() => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// 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.
|
||||
//
|
||||
|
|
@ -8,13 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test that the trace_macros feature gate is on.
|
||||
// checks that this attribute is caught on non-macro items.
|
||||
// this needs a different test since this is done after expansion
|
||||
|
||||
fn main() {
|
||||
// (Infrastructure does not attempt to detect uses in macro definitions.)
|
||||
macro_rules! expando {
|
||||
($x: ident) => { trace_macros!($x) }
|
||||
}
|
||||
#[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps
|
||||
struct S;
|
||||
|
||||
expando!(true); //~ ERROR `trace_macros` is not stable
|
||||
}
|
||||
fn main() {}
|
||||
33
src/test/compile-fail/issue-32655.rs
Normal file
33
src/test/compile-fail/issue-32655.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// 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 <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.
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
macro_rules! foo (
|
||||
() => (
|
||||
#[derive_Clone] //~ WARN attributes of the form
|
||||
struct T;
|
||||
);
|
||||
);
|
||||
|
||||
macro_rules! bar (
|
||||
($e:item) => ($e)
|
||||
);
|
||||
|
||||
foo!();
|
||||
|
||||
bar!(
|
||||
#[derive_Clone] //~ WARN attributes of the form
|
||||
struct S;
|
||||
);
|
||||
|
||||
#[rustc_error]
|
||||
fn main() {} //~ ERROR compilation successful
|
||||
23
src/test/compile-fail/issue-32782.rs
Normal file
23
src/test/compile-fail/issue-32782.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// 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 <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.
|
||||
|
||||
macro_rules! bar (
|
||||
() => ()
|
||||
);
|
||||
|
||||
macro_rules! foo (
|
||||
() => (
|
||||
#[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps
|
||||
bar!();
|
||||
);
|
||||
);
|
||||
|
||||
foo!();
|
||||
fn main() {}
|
||||
|
|
@ -26,5 +26,5 @@ fn main() {
|
|||
($x: ident) => { trace_macros!($x) }
|
||||
}
|
||||
|
||||
expando!(true);
|
||||
expando!(true); //~ ERROR `trace_macros` is not stable
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
// 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.
|
||||
|
||||
// Test that the trace_macros feature gate is on.
|
||||
|
||||
pub fn main() {
|
||||
println!("arg: {}", trace_macros!()); //~ ERROR `trace_macros` is not stable
|
||||
println!("arg: {}", trace_macros!(1)); //~ ERROR `trace_macros` is not stable
|
||||
println!("arg: {}", trace_macros!(ident)); //~ ERROR `trace_macros` is not stable
|
||||
println!("arg: {}", trace_macros!(for)); //~ ERROR `trace_macros` is not stable
|
||||
println!("arg: {}", trace_macros!(true,)); //~ ERROR `trace_macros` is not stable
|
||||
println!("arg: {}", trace_macros!(false 1)); //~ ERROR `trace_macros` is not stable
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue