-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement RFC 2539: cfg_attr with multiple attributes #54862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9568ec6
Move conditional configuration related UI tests into their own directory
Havvy 1a867dc
cfg_attr_multi: Basic implementation
Havvy 35e6c65
cfg_attr_multi: Feature gate
Havvy bbe832d
cfg-attr-multi: Change issue number to actual tracking issue
Havvy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe premature, but have you considered using SmallVec to save an allocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to measure whether or not that would be a win. And yes, it's a bit premature, since I want to get the code right first.