Skip to content

Commit 63c8f37

Browse files
authored
better error messages for target-feature detection macros (rust-lang#352)
Better error messages for target-feature detection macros
1 parent 93b9957 commit 63c8f37

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

stdsimd/arch/detect/mod.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,72 @@ pub use self::arch::Feature;
3636
pub fn check_for(x: Feature) -> bool {
3737
cache::test(x as u32, arch::detect_features)
3838
}
39+
40+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
41+
#[macro_export]
42+
#[unstable(feature = "stdsimd", issue = "0")]
43+
macro_rules! is_x86_feature_detected {
44+
($t:tt) => {
45+
compile_error!(r#"
46+
is_x86_feature_detected can only be used on x86 and x86_64 targets.
47+
You can prevent it from being used in other architectures by
48+
guarding it behind a cfg(target_arch) as follows:
49+
50+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
51+
if is_x86_feature_detected(...) { ... }
52+
}
53+
"#)
54+
};
55+
}
56+
57+
#[cfg(not(target_arch = "arm"))]
58+
#[macro_export]
59+
#[unstable(feature = "stdsimd", issue = "0")]
60+
macro_rules! is_arm_feature_detected {
61+
($t:tt) => {
62+
compile_error!(r#"
63+
is_arm_feature_detected can only be used on ARM targets.
64+
You can prevent it from being used in other architectures by
65+
guarding it behind a cfg(target_arch) as follows:
66+
67+
#[cfg(target_arch = "arm")] {
68+
if is_arm_feature_detected(...) { ... }
69+
}
70+
"#)
71+
};
72+
}
73+
74+
#[cfg(not(target_arch = "aarch64"))]
75+
#[macro_export]
76+
#[unstable(feature = "stdsimd", issue = "0")]
77+
macro_rules! is_aarch64_feature_detected {
78+
($t:tt) => {
79+
compile_error!(r#"
80+
is_aarch64_feature_detected can only be used on AArch64 targets.
81+
You can prevent it from being used in other architectures by
82+
guarding it behind a cfg(target_arch) as follows:
83+
84+
#[cfg(target_arch = "aarch64")] {
85+
if is_aarch64_feature_detected(...) { ... }
86+
}
87+
"#)
88+
};
89+
}
90+
91+
#[cfg(not(target_arch = "powerpc64"))]
92+
#[macro_export]
93+
#[unstable(feature = "stdsimd", issue = "0")]
94+
macro_rules! is_powerpc64_feature_detected {
95+
($t:tt) => {
96+
compile_error!(r#"
97+
is_powerpc64_feature_detected can only be used on PowerPC64 targets.
98+
You can prevent it from being used in other architectures by
99+
guarding it behind a cfg(target_arch) as follows:
100+
101+
#[cfg(target_arch = "powerpc64")] {
102+
if is_powerpc64_feature_detected(...) { ... }
103+
}
104+
"#)
105+
};
106+
}
107+

0 commit comments

Comments
 (0)