Skip to content

Commit 2363790

Browse files
alexcrichtongnzlbg
authored andcommitted
Remove need for #[macro_use] with cfg-if
Modernizes usage of `cfg_if!` slightly
1 parent 8640954 commit 2363790

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

crates/std_detect/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
keywords = ["std", "run-time", "feature", "detection"]
1515
categories = ["hardware-support"]
1616
license = "MIT/Apache-2.0"
17-
edition = "2015"
17+
edition = "2018"
1818

1919
[badges]
2020
is-it-maintained-issue-resolution = { repository = "rust-lang/stdarch" }
@@ -23,7 +23,7 @@ maintenance = { status = "experimental" }
2323

2424
[dependencies]
2525
libc = { version = "0.2", optional = true, default-features = false }
26-
cfg-if = "0.1"
26+
cfg-if = "0.1.10"
2727

2828
[dev-dependencies]
2929
auxv = "0.3.3"

crates/std_detect/src/detect/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Cache {
158158
self.1.store(hi, Ordering::Relaxed);
159159
}
160160
}
161-
cfg_if! {
161+
cfg_if::cfg_if! {
162162
if #[cfg(feature = "std_detect_env_override")] {
163163
#[inline(never)]
164164
fn initialize(mut value: Initializer) {

crates/std_detect/src/detect/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//! due to security concerns (x86 is the big exception). These functions are
1818
//! implemented in the `os/{target_os}.rs` modules.
1919
20+
use cfg_if::cfg_if;
21+
2022
#[macro_use]
2123
mod error_macros;
2224

@@ -132,19 +134,14 @@ pub fn features() -> impl Iterator<Item = (&'static str, bool)> {
132134
target_arch = "mips",
133135
target_arch = "mips64",
134136
))] {
135-
fn impl_() -> impl Iterator<Item=(&'static str, bool)> {
136-
(0_u8..Feature::_last as u8).map(|discriminant: u8| {
137-
let f: Feature = unsafe { crate::mem::transmute(discriminant) };
138-
let name: &'static str = f.to_str();
139-
let enabled: bool = check_for(f);
140-
(name, enabled)
141-
})
142-
}
137+
(0_u8..Feature::_last as u8).map(|discriminant: u8| {
138+
let f: Feature = unsafe { crate::mem::transmute(discriminant) };
139+
let name: &'static str = f.to_str();
140+
let enabled: bool = check_for(f);
141+
(name, enabled)
142+
})
143143
} else {
144-
fn impl_() -> impl Iterator<Item=(&'static str, bool)> {
145-
(0_u8..0_u8).map(|_x: u8| ("", false))
146-
}
144+
None.into_iter()
147145
}
148146
}
149-
impl_()
150147
}

crates/std_detect/src/detect/os/freebsd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
mod auxvec;
44

5-
cfg_if! {
5+
cfg_if::cfg_if! {
66
if #[cfg(target_arch = "aarch64")] {
77
mod aarch64;
88
pub use self::aarch64::check_for;

crates/std_detect/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
#![cfg_attr(test, allow(unused_imports))]
2121
#![no_std]
2222

23-
#[macro_use]
24-
extern crate cfg_if;
25-
26-
cfg_if! {
23+
cfg_if::cfg_if! {
2724
if #[cfg(any(feature = "std_detect_file_io", feature = "std_detect_env_override"))] {
2825
#[cfg_attr(test, macro_use(println))]
2926
extern crate std;

0 commit comments

Comments
 (0)