Skip to content

Commit b4a0e07

Browse files
Amanieubjorn3
andauthored
Avoid the use of #[cfg(doc)] in std_detect (#1283)
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
1 parent 863d31b commit b4a0e07

File tree

12 files changed

+115
-271
lines changed

12 files changed

+115
-271
lines changed

crates/std_detect/src/detect/arch/aarch64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: aarch64;
5+
@CFG: target_arch = "aarch64";
56
@MACRO_NAME: is_aarch64_feature_detected;
67
@MACRO_ATTRS:
78
/// This macro tests, at runtime, whether an `aarch64` feature is enabled on aarch64 platforms.

crates/std_detect/src/detect/arch/arm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: arm;
5+
@CFG: target_arch = "arm";
56
@MACRO_NAME: is_arm_feature_detected;
67
@MACRO_ATTRS:
78
/// Checks if `arm` feature is enabled.

crates/std_detect/src/detect/arch/mips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: mips;
5+
@CFG: target_arch = "mips";
56
@MACRO_NAME: is_mips_feature_detected;
67
@MACRO_ATTRS:
78
/// Checks if `mips` feature is enabled.

crates/std_detect/src/detect/arch/mips64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: mips64;
5+
@CFG: target_arch = "mips64";
56
@MACRO_NAME: is_mips64_feature_detected;
67
@MACRO_ATTRS:
78
/// Checks if `mips64` feature is enabled.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![allow(dead_code)]
2+
3+
use cfg_if::cfg_if;
4+
5+
// Export the macros for all supported architectures.
6+
#[macro_use]
7+
mod x86;
8+
#[macro_use]
9+
mod arm;
10+
#[macro_use]
11+
mod aarch64;
12+
#[macro_use]
13+
mod riscv;
14+
#[macro_use]
15+
mod powerpc;
16+
#[macro_use]
17+
mod powerpc64;
18+
#[macro_use]
19+
mod mips;
20+
#[macro_use]
21+
mod mips64;
22+
23+
cfg_if! {
24+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
25+
pub use x86::*;
26+
} else if #[cfg(target_arch = "arm")] {
27+
pub use arm::*;
28+
} else if #[cfg(target_arch = "aarch64")] {
29+
pub use aarch64::*;
30+
} else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] {
31+
pub use riscv::*;
32+
} else if #[cfg(target_arch = "powerpc")] {
33+
pub use powerpc::*;
34+
} else if #[cfg(target_arch = "powerpc64")] {
35+
pub use powerpc64::*;
36+
} else if #[cfg(target_arch = "mips")] {
37+
pub use mips::*;
38+
} else if #[cfg(target_arch = "mips64")] {
39+
pub use mips64::*;
40+
} else {
41+
// Unimplemented architecture:
42+
#[doc(hidden)]
43+
pub(crate) enum Feature {
44+
Null
45+
}
46+
#[doc(hidden)]
47+
pub mod __is_feature_detected {}
48+
49+
impl Feature {
50+
#[doc(hidden)]
51+
pub(crate) fn from_str(_s: &str) -> Result<Feature, ()> { Err(()) }
52+
#[doc(hidden)]
53+
pub(crate) fn to_str(self) -> &'static str { "" }
54+
}
55+
}
56+
}

crates/std_detect/src/detect/arch/powerpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: powerpc;
5+
@CFG: target_arch = "powerpc";
56
@MACRO_NAME: is_powerpc_feature_detected;
67
@MACRO_ATTRS:
78
/// Checks if `powerpc` feature is enabled.

crates/std_detect/src/detect/arch/powerpc64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: powerpc64;
5+
@CFG: target_arch = "powerpc64";
56
@MACRO_NAME: is_powerpc64_feature_detected;
67
@MACRO_ATTRS:
78
/// Checks if `powerpc` feature is enabled.

crates/std_detect/src/detect/arch/riscv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
features! {
44
@TARGET: riscv;
5+
@CFG: any(target_arch = "riscv32", target_arch = "riscv64");
56
@MACRO_NAME: is_riscv_feature_detected;
67
@MACRO_ATTRS:
78
/// A macro to test at *runtime* whether instruction sets are available on

crates/std_detect/src/detect/arch/x86.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
features! {
1919
@TARGET: x86;
20+
@CFG: any(target_arch = "x86", target_arch = "x86_64");
2021
@MACRO_NAME: is_x86_feature_detected;
2122
@MACRO_ATTRS:
2223
/// A macro to test at *runtime* whether a CPU feature is available on

crates/std_detect/src/detect/error_macros.rs

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)