forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#54862 - Havvy:cfg_attr_multi, r=petrochenkov
Fixes rust-lang#47311. r? @nrc
- Loading branch information
Showing
44 changed files
with
360 additions
and
46 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/doc/unstable-book/src/language-features/cfg-attr-multi.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
src/test/ui/conditional-compilation/cfg-attr-multi-false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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)] | ||
#![feature(cfg_attr_multi)] | ||
|
||
#[cfg_attr(any(), deprecated, must_use)] | ||
struct Struct {} | ||
|
||
impl Struct { | ||
fn new() -> Struct { | ||
Struct {} | ||
} | ||
} | ||
|
||
fn main() { | ||
Struct::new(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/conditional-compilation/cfg-attr-multi-invalid-1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 | ||
|
||
#![feature(cfg_attr_multi)] | ||
#![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental | ||
|
||
fn main() { } |
11 changes: 11 additions & 0 deletions
11
src/test/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0658]: no_core is experimental (see issue #29639) | ||
--> $DIR/cfg-attr-multi-invalid-1.rs:14: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`. |
16 changes: 16 additions & 0 deletions
16
src/test/ui/conditional-compilation/cfg-attr-multi-invalid-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 | ||
|
||
#![feature(cfg_attr_multi)] | ||
#![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental | ||
|
||
fn main() { } |
11 changes: 11 additions & 0 deletions
11
src/test/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0658]: no_core is experimental (see issue #29639) | ||
--> $DIR/cfg-attr-multi-invalid-2.rs:14: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`. |
22 changes: 22 additions & 0 deletions
22
src/test/ui/conditional-compilation/cfg-attr-multi-true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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)] | ||
#![feature(cfg_attr_multi)] | ||
|
||
#[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 | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/conditional-compilation/cfg-attr-multi-true.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
warning: use of deprecated item 'MustUseDeprecated' | ||
--> $DIR/cfg-attr-multi-true.rs:13: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:20:5 | ||
| | ||
LL | MustUseDeprecated::new(); //~ warning: use of deprecated item | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of deprecated item 'MustUseDeprecated' | ||
--> $DIR/cfg-attr-multi-true.rs:14:17 | ||
| | ||
LL | fn new() -> MustUseDeprecated { //~ warning: use of deprecated item | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of deprecated item 'MustUseDeprecated' | ||
--> $DIR/cfg-attr-multi-true.rs:15:9 | ||
| | ||
LL | MustUseDeprecated {} //~ warning: use of deprecated item | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
warning: unused `MustUseDeprecated` which must be used | ||
--> $DIR/cfg-attr-multi-true.rs:20: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)] | ||
| ^^^^^^^^^^^^^^^ | ||
|
Oops, something went wrong.