cfg_attr_multi: Basic implementation
Does not implement the warning or a feature flag.
This commit is contained in:
parent
9568ec6bef
commit
1a867dc346
14 changed files with 252 additions and 45 deletions
|
|
@ -1,13 +0,0 @@
|
|||
// compile-flags: --cfg TRUE
|
||||
|
||||
#[cfg_attr(TRUE, inline,)] // OK
|
||||
fn f() {}
|
||||
|
||||
#[cfg_attr(FALSE, inline,)] // OK
|
||||
fn g() {}
|
||||
|
||||
#[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
|
||||
fn h() {}
|
||||
|
||||
#[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
|
||||
fn i() {}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: expected `)`, found `,`
|
||||
--> $DIR/cfg-attr-trailing-comma.rs:9:25
|
||||
|
|
||||
LL | #[cfg_attr(TRUE, inline,,)] //~ ERROR expected `)`, found `,`
|
||||
| ^ expected `)`
|
||||
|
||||
error: expected `)`, found `,`
|
||||
--> $DIR/cfg-attr-trailing-comma.rs:12:26
|
||||
|
|
||||
LL | #[cfg_attr(FALSE, inline,,)] //~ ERROR expected `)`, found `,`
|
||||
| ^ expected `)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ error[E0658]: no_core is experimental (see issue #29639)
|
|||
--> $DIR/cfg-attr-crate-2.rs:15:21
|
||||
|
|
||||
LL | #![cfg_attr(broken, no_core)] //~ ERROR no_core is experimental
|
||||
| ^^^^^^^^
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: add #![feature(no_core)] to the crate attributes to enable
|
||||
|
||||
|
|
|
|||
19
src/test/ui/conditional-compilation/cfg-attr-multi-false.rs
Normal file
19
src/test/ui/conditional-compilation/cfg-attr-multi-false.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Test that cfg_attr doesn't emit any attributes when the
|
||||
// configuation variable is false. This mirrors `cfg-attr-multi-true.rs`
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![warn(unused_must_use)]
|
||||
|
||||
#[cfg_attr(any(), deprecated, must_use)]
|
||||
struct Struct {}
|
||||
|
||||
impl Struct {
|
||||
fn new() -> Struct {
|
||||
Struct {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Struct::new();
|
||||
}
|
||||
|
|
@ -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.
|
||||
//
|
||||
// compile-flags: --cfg broken
|
||||
|
||||
#![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0658]: no_core is experimental (see issue #29639)
|
||||
--> $DIR/cfg-attr-multi-invalid-1.rs:13:21
|
||||
|
|
||||
LL | #![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: add #![feature(no_core)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -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.
|
||||
//
|
||||
// compile-flags: --cfg broken
|
||||
|
||||
#![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0658]: no_core is experimental (see issue #29639)
|
||||
--> $DIR/cfg-attr-multi-invalid-2.rs:13:29
|
||||
|
|
||||
LL | #![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: add #![feature(no_core)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
21
src/test/ui/conditional-compilation/cfg-attr-multi-true.rs
Normal file
21
src/test/ui/conditional-compilation/cfg-attr-multi-true.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Test that cfg_attr with multiple attributes actually emits both attributes.
|
||||
// This is done by emitting two attributes that cause new warnings, and then
|
||||
// triggering those warnings.
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![warn(unused_must_use)]
|
||||
|
||||
#[cfg_attr(all(), deprecated, must_use)]
|
||||
struct MustUseDeprecated {}
|
||||
|
||||
impl MustUseDeprecated { //~ warning: use of deprecated item
|
||||
fn new() -> MustUseDeprecated { //~ warning: use of deprecated item
|
||||
MustUseDeprecated {} //~ warning: use of deprecated item
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
MustUseDeprecated::new(); //~ warning: use of deprecated item
|
||||
//| warning: unused `MustUseDeprecated` which must be used
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
warning: use of deprecated item 'MustUseDeprecated'
|
||||
--> $DIR/cfg-attr-multi-true.rs:12:6
|
||||
|
|
||||
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:19:5
|
||||
|
|
||||
LL | MustUseDeprecated::new(); //~ warning: use of deprecated item
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: use of deprecated item 'MustUseDeprecated'
|
||||
--> $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:14:9
|
||||
|
|
||||
LL | MustUseDeprecated {} //~ warning: use of deprecated item
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: unused `MustUseDeprecated` which must be used
|
||||
--> $DIR/cfg-attr-multi-true.rs:19:5
|
||||
|
|
||||
LL | MustUseDeprecated::new(); //~ warning: use of deprecated item
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/cfg-attr-multi-true.rs:7:9
|
||||
|
|
||||
LL | #![warn(unused_must_use)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
45
src/test/ui/conditional-compilation/cfg-attr-parse.rs
Normal file
45
src/test/ui/conditional-compilation/cfg-attr-parse.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// 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;
|
||||
|
||||
// Zero attributes, zero trailing comma (comma manatory here)
|
||||
#[cfg_attr(all())] //~ error: expected `,`, found `)`
|
||||
struct A0C0;
|
||||
|
||||
// Zero attributes, one trailing comma
|
||||
#[cfg_attr(all(),)] // Ok
|
||||
struct A0C1;
|
||||
|
||||
// Zero attributes, two trailing commas
|
||||
#[cfg_attr(all(),,)] //~ ERROR expected identifier
|
||||
struct A0C2;
|
||||
|
||||
// One attribute, no trailing comma
|
||||
#[cfg_attr(all(), must_use)] // Ok
|
||||
struct A1C0;
|
||||
|
||||
// One attribute, one trailing comma
|
||||
#[cfg_attr(all(), must_use,)] // Ok
|
||||
struct A1C1;
|
||||
|
||||
// One attribute, two trailing commas
|
||||
#[cfg_attr(all(), must_use,,)] //~ ERROR expected identifier
|
||||
struct A1C2;
|
||||
|
||||
// Two attributes, no trailing comma
|
||||
#[cfg_attr(all(), must_use, deprecated)] // Ok
|
||||
struct A2C0;
|
||||
|
||||
// Two attributes, one trailing comma
|
||||
#[cfg_attr(all(), must_use, deprecated,)] // Ok
|
||||
struct A2C1;
|
||||
|
||||
// Two attributes, two trailing commas
|
||||
#[cfg_attr(all(), must_use, deprecated,,)] //~ ERROR expected identifier
|
||||
struct A2C2;
|
||||
|
||||
fn main() {}
|
||||
32
src/test/ui/conditional-compilation/cfg-attr-parse.stderr
Normal file
32
src/test/ui/conditional-compilation/cfg-attr-parse.stderr
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
error: expected identifier, found `)`
|
||||
--> $DIR/cfg-attr-parse.rs:6:12
|
||||
|
|
||||
LL | #[cfg_attr()] //~ error: expected identifier, found `)`
|
||||
| ^ expected identifier
|
||||
|
||||
error: expected `,`, found `)`
|
||||
--> $DIR/cfg-attr-parse.rs:10:17
|
||||
|
|
||||
LL | #[cfg_attr(all())] //~ error: expected `,`, found `)`
|
||||
| ^ expected `,`
|
||||
|
||||
error: expected identifier, found `,`
|
||||
--> $DIR/cfg-attr-parse.rs:18:18
|
||||
|
|
||||
LL | #[cfg_attr(all(),,)] //~ ERROR expected identifier
|
||||
| ^ expected identifier
|
||||
|
||||
error: expected identifier, found `,`
|
||||
--> $DIR/cfg-attr-parse.rs:30:28
|
||||
|
|
||||
LL | #[cfg_attr(all(), must_use,,)] //~ ERROR expected identifier
|
||||
| ^ expected identifier
|
||||
|
||||
error: expected identifier, found `,`
|
||||
--> $DIR/cfg-attr-parse.rs:42:40
|
||||
|
|
||||
LL | #[cfg_attr(all(), must_use, deprecated,,)] //~ ERROR expected identifier
|
||||
| ^ expected identifier
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue