Auto merge of #57332 - Dylan-DPC:feature/stabilise-cfg-attr, r=Centril

stabilize cfg_attr_multi

Stabilizes cfg_attr_multi feature

Related to #54881

Will add the lint in a seperate PR

r? @Centril
This commit is contained in:
bors 2019-01-08 07:49:13 +00:00
commit 7ad470c0a6
18 changed files with 16 additions and 110 deletions

View File

@ -1,20 +0,0 @@
# `cfg_attr_multi`
The tracking issue for this feature is: [#54881]
The RFC for this feature is: [#2539]
[#54881]: https://github.com/rust-lang/rust/issues/54881
[#2539]: https://github.com/rust-lang/rfcs/pull/2539
------------------------
This feature flag lets you put multiple attributes into a `cfg_attr` attribute.
Example:
```rust,ignore
#[cfg_attr(all(), must_use, optimize)]
```
Because `cfg_attr` resolves before procedural macros, this does not affect
macro resolution at all.

View File

@ -5,7 +5,6 @@ use feature_gate::{
Features,
get_features,
GateIssue,
emit_feature_err,
};
use {fold, attr};
use ast;
@ -94,13 +93,6 @@ impl<'a> StripUnconfigured<'a> {
return vec![attr];
}
let gate_cfg_attr_multi = if let Some(ref features) = self.features {
!features.cfg_attr_multi
} else {
false
};
let cfg_attr_span = attr.span;
let (cfg_predicate, expanded_attrs) = match attr.parse(self.sess, |parser| {
parser.expect(&token::OpenDelim(token::Paren))?;
@ -130,21 +122,8 @@ impl<'a> StripUnconfigured<'a> {
// Check feature gate and lint on zero attributes in source. Even if the feature is gated,
// we still compute as if it wasn't, since the emitted error will stop compilation further
// along the compilation.
match (expanded_attrs.len(), gate_cfg_attr_multi) {
(0, false) => {
// FIXME: Emit unused attribute lint here.
},
(1, _) => {},
(_, true) => {
emit_feature_err(
self.sess,
"cfg_attr_multi",
cfg_attr_span,
GateIssue::Language,
"cfg_attr with zero or more than one attributes is experimental",
);
},
(_, false) => {}
if expanded_attrs.len() == 0 {
// FIXME: Emit unused attribute lint here.
}
if attr::cfg_matches(&cfg_predicate, self.sess, self.features) {

View File

@ -465,9 +465,6 @@ declare_features! (
// Allows `impl Trait` in bindings (`let`, `const`, `static`).
(active, impl_trait_in_bindings, "1.30.0", Some(34511), None),
// `#[cfg_attr(predicate, multiple, attributes, here)]`
(active, cfg_attr_multi, "1.31.0", Some(54881), None),
// Allows `const _: TYPE = VALUE`.
(active, underscore_const_names, "1.31.0", Some(54912), None),
@ -689,6 +686,8 @@ declare_features! (
(accepted, repr_packed, "1.33.0", Some(33158), None),
// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions.
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None),
// `#[cfg_attr(predicate, multiple, attributes, here)]`
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
);
// If you change this, please modify `src/doc/unstable-book` as well. You must

View File

@ -4,7 +4,6 @@
// compile-pass
#![warn(unused_must_use)]
#![feature(cfg_attr_multi)]
#[cfg_attr(any(), deprecated, must_use)]
struct Struct {}

View File

@ -1,6 +1,5 @@
// compile-flags: --cfg broken
#![feature(cfg_attr_multi)]
#![crate_type = "lib"]
#![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental

View File

@ -1,5 +1,5 @@
error[E0658]: no_core is experimental (see issue #29639)
--> $DIR/cfg-attr-multi-invalid-1.rs:5:21
--> $DIR/cfg-attr-multi-invalid-1.rs:4:21
|
LL | #![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental
| ^^^^^^^

View File

@ -1,6 +1,5 @@
// compile-flags: --cfg broken
#![feature(cfg_attr_multi)]
#![crate_type = "lib"]
#![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental

View File

@ -1,5 +1,5 @@
error[E0658]: no_core is experimental (see issue #29639)
--> $DIR/cfg-attr-multi-invalid-2.rs:5:29
--> $DIR/cfg-attr-multi-invalid-2.rs:4:29
|
LL | #![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental
| ^^^^^^^

View File

@ -5,7 +5,6 @@
// compile-pass
#![warn(unused_must_use)]
#![feature(cfg_attr_multi)]
#[cfg_attr(all(), deprecated, must_use)]
struct MustUseDeprecated {}

View File

@ -1,5 +1,5 @@
warning: use of deprecated item 'MustUseDeprecated'
--> $DIR/cfg-attr-multi-true.rs:13:6
--> $DIR/cfg-attr-multi-true.rs:12:6
|
LL | impl MustUseDeprecated { //~ warning: use of deprecated item
| ^^^^^^^^^^^^^^^^^
@ -7,25 +7,25 @@ LL | impl MustUseDeprecated { //~ warning: use of deprecated item
= note: #[warn(deprecated)] on by default
warning: use of deprecated item 'MustUseDeprecated'
--> $DIR/cfg-attr-multi-true.rs:20:5
--> $DIR/cfg-attr-multi-true.rs:19:5
|
LL | MustUseDeprecated::new(); //~ warning: use of deprecated item
| ^^^^^^^^^^^^^^^^^^^^^^
warning: use of deprecated item 'MustUseDeprecated'
--> $DIR/cfg-attr-multi-true.rs:14:17
--> $DIR/cfg-attr-multi-true.rs:13:17
|
LL | fn new() -> MustUseDeprecated { //~ warning: use of deprecated item
| ^^^^^^^^^^^^^^^^^
warning: use of deprecated item 'MustUseDeprecated'
--> $DIR/cfg-attr-multi-true.rs:15:9
--> $DIR/cfg-attr-multi-true.rs:14:9
|
LL | MustUseDeprecated {} //~ warning: use of deprecated item
| ^^^^^^^^^^^^^^^^^
warning: unused `MustUseDeprecated` that must be used
--> $DIR/cfg-attr-multi-true.rs:20:5
--> $DIR/cfg-attr-multi-true.rs:19:5
|
LL | MustUseDeprecated::new(); //~ warning: use of deprecated item
| ^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,7 +1,5 @@
// Parse `cfg_attr` with varying numbers of attributes and trailing commas
#![feature(cfg_attr_multi)]
// Completely empty `cfg_attr` input
#[cfg_attr()] //~ error: expected identifier, found `)`
struct NoConfigurationPredicate;

View File

@ -1,29 +1,29 @@
error: expected identifier, found `)`
--> $DIR/cfg-attr-parse.rs:6:12
--> $DIR/cfg-attr-parse.rs:4:12
|
LL | #[cfg_attr()] //~ error: expected identifier, found `)`
| ^ expected identifier
error: expected `,`, found `)`
--> $DIR/cfg-attr-parse.rs:10:17
--> $DIR/cfg-attr-parse.rs:8:17
|
LL | #[cfg_attr(all())] //~ error: expected `,`, found `)`
| ^ expected `,`
error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:18:18
--> $DIR/cfg-attr-parse.rs:16:18
|
LL | #[cfg_attr(all(),,)] //~ ERROR expected identifier
| ^ expected identifier
error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:30:28
--> $DIR/cfg-attr-parse.rs:28:28
|
LL | #[cfg_attr(all(), must_use,,)] //~ ERROR expected identifier
| ^ expected identifier
error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:42:40
--> $DIR/cfg-attr-parse.rs:40:40
|
LL | #[cfg_attr(all(), must_use, deprecated,,)] //~ ERROR expected identifier
| ^ expected identifier

View File

@ -1,5 +0,0 @@
// gate-test-cfg_attr_multi
#![cfg_attr(all(), warn(nonstandard_style), allow(unused_attributes))]
//~^ ERROR cfg_attr with zero or more than one attributes is experimental
fn main() {}

View File

@ -1,11 +0,0 @@
error[E0658]: cfg_attr with zero or more than one attributes is experimental (see issue #54881)
--> $DIR/feature-gate-cfg-attr-multi-1.rs:3:1
|
LL | #![cfg_attr(all(), warn(nonstandard_style), allow(unused_attributes))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(cfg_attr_multi)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,3 +0,0 @@
#![cfg_attr(all(),)]
//~^ ERROR cfg_attr with zero or more than one attributes is experimental
fn main() {}

View File

@ -1,11 +0,0 @@
error[E0658]: cfg_attr with zero or more than one attributes is experimental (see issue #54881)
--> $DIR/feature-gate-cfg-attr-multi-2.rs:1:1
|
LL | #![cfg_attr(all(),)]
| ^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(cfg_attr_multi)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,7 +0,0 @@
// Test that settingt the featute gate while using its functionality doesn't error.
// compile-pass
#![cfg_attr(all(), feature(cfg_attr_multi), crate_type="bin")]
fn main() {}

View File

@ -1,9 +0,0 @@
// Test that settingt the featute gate while using its functionality doesn't error.
// Specifically, if there's a cfg-attr *before* the feature gate.
// compile-pass
#![cfg_attr(all(),)]
#![cfg_attr(all(), feature(cfg_attr_multi), crate_type="bin")]
fn main() {}