-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add unstable cfg_if! macro to libcore #59443
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
97f2005
Add unstable cfg_if! macro to libcore
gnzlbg c0aabcf
Remove cfg_if macro from libstd
gnzlbg 3e9d356
Test that cfg_if from prelude can be overriden
gnzlbg 52bd6ad
Add test that overrides cfg_if with the one from crates.io
gnzlbg f35f2df
Enable cfg_if feature for libstd
gnzlbg 72eed28
cfg_if doc-example should use the macro from libcore
gnzlbg f6fbf93
Remove unnecessary feature(cfg_if)
gnzlbg 881b592
Fix typo in name of the cfg-if dev-dependency
gnzlbg 168229b
Re-export cfg_if macro from libstd and test
gnzlbg f915ae4
Choose right cfg-if version number
gnzlbg 165882c
Update Cargo.lock
gnzlbg 98e1461
fix build
gnzlbg 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
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 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,52 @@ | ||
#![feature(cfg_if)] | ||
|
||
cfg_if! { | ||
if #[cfg(test)] { | ||
use core::option::Option as Option2; | ||
fn works1() -> Option2<u32> { Some(1) } | ||
} else { | ||
fn works1() -> Option<u32> { None } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works2() -> bool { false } | ||
} else if #[cfg(test)] { | ||
fn works2() -> bool { true } | ||
} else { | ||
fn works2() -> bool { false } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works3() -> bool { false } | ||
} else { | ||
fn works3() -> bool { true } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(test)] { | ||
use core::option::Option as Option3; | ||
fn works4() -> Option3<u32> { Some(1) } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works5() -> bool { false } | ||
} else if #[cfg(test)] { | ||
fn works5() -> bool { true } | ||
} | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
assert!(works1().is_some()); | ||
assert!(works2()); | ||
assert!(works3()); | ||
assert!(works4().is_some()); | ||
assert!(works5()); | ||
} |
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,17 @@ | ||
//! Test that overriding cfg_if with our own cfg_if macro does not break | ||
//! anything. | ||
|
||
macro_rules! cfg_if { | ||
(()) => { | ||
mod foo { | ||
fn foo() {} | ||
} | ||
} | ||
} | ||
|
||
cfg_if!{} | ||
|
||
#[test] | ||
fn it_works() { | ||
foo::foo(); | ||
} |
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,55 @@ | ||
//! Test that using cfg_if from the cfg_if crate does not break anything. | ||
|
||
#[macro_use(cfg_if)] | ||
extern crate cfg_if; | ||
|
||
cfg_if! { | ||
if #[cfg(test)] { | ||
use core::option::Option as Option2; | ||
fn works1() -> Option2<u32> { Some(1) } | ||
} else { | ||
fn works1() -> Option<u32> { None } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works2() -> bool { false } | ||
} else if #[cfg(test)] { | ||
fn works2() -> bool { true } | ||
} else { | ||
fn works2() -> bool { false } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works3() -> bool { false } | ||
} else { | ||
fn works3() -> bool { true } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(test)] { | ||
use core::option::Option as Option3; | ||
fn works4() -> Option3<u32> { Some(1) } | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(foo)] { | ||
fn works5() -> bool { false } | ||
} else if #[cfg(test)] { | ||
fn works5() -> bool { true } | ||
} | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
assert!(works1().is_some()); | ||
assert!(works2()); | ||
assert!(works3()); | ||
assert!(works4().is_some()); | ||
assert!(works5()); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![feature(cfg_if)] | ||
pub use std::cfg_if; | ||
|
||
cfg_if! { | ||
if #[cfg(test)] { | ||
fn foo() -> bool { true } | ||
} else { | ||
fn foo() -> bool { false } | ||
} | ||
} | ||
|
||
#[test] | ||
fn cfg_if_test() { | ||
assert!(foo()); | ||
} |
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.
Use
$crate::
instead?