Skip to content

Commit 6f06843

Browse files
zzau13gnzlbg
authored andcommitted
Add detect macros should support trailing commas (Fix #443)
1 parent 0322e20 commit 6f06843

File tree

8 files changed

+76
-0
lines changed

8 files changed

+76
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ macro_rules! is_aarch64_feature_detected {
6666
("v8.3a") => {
6767
compile_error!("\"v8.3a\" feature cannot be detected at run-time")
6868
};
69+
($t:tt,) => {
70+
is_aarch64_feature_detected!($t);
71+
};
6972
($t:tt) => { compile_error!(concat!("unknown aarch64 target feature: ", $t)) };
7073
}
7174

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ macro_rules! is_arm_feature_detected {
1717
("vfp2") => { compile_error!("\"vfp2\" feature cannot be detected at run-time") };
1818
("vfp3") => { compile_error!("\"vfp3\" feature cannot be detected at run-time") };
1919
("vfp4") => { compile_error!("\"vfp4\" feature cannot be detected at run-time") };
20+
($t:tt,) => {
21+
is_arm_feature_detected!($t);
22+
};
2023
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
2124
}
2225

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ macro_rules! is_mips_feature_detected {
99
cfg!(target_feature = "msa") ||
1010
$crate::detect::check_for($crate::detect::Feature::msa)
1111
};
12+
($t:tt,) => {
13+
is_mips_feature_detected!($t);
14+
};
1215
($t:tt) => { compile_error!(concat!("unknown mips target feature: ", $t)) };
1316
}
1417

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ macro_rules! is_mips64_feature_detected {
99
cfg!(target_feature = "msa") ||
1010
$crate::detect::check_for($crate::detect::Feature::msa)
1111
};
12+
($t:tt,) => {
13+
is_mips64_feature_detected!($t);
14+
};
1215
($t:tt) => { compile_error!(concat!("unknown mips64 target feature: ", $t)) };
1316
}
1417

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ macro_rules! is_powerpc_feature_detected {
1717
cfg!(target_feature = "power8") ||
1818
$crate::detect::check_for($crate::detect::Feature::power8)
1919
};
20+
($t:tt,) => {
21+
is_powerpc_feature_detected!($t);
22+
};
2023
($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) };
2124
}
2225

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ macro_rules! is_powerpc64_feature_detected {
1717
cfg!(target_feature = "power8") ||
1818
$crate::detect::check_for($crate::detect::Feature::power8)
1919
};
20+
($t:tt,) => {
21+
is_powerpc64_feature_detected!($t);
22+
};
2023
($t:tt) => { compile_error!(concat!("unknown powerpc64 target feature: ", $t)) };
2124
}
2225

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ macro_rules! is_x86_feature_detected {
234234
cfg!(target_feature = "adx") || $crate::detect::check_for(
235235
$crate::detect::Feature::adx)
236236
};
237+
($t:tt,) => {
238+
is_x86_feature_detected!($t);
239+
};
237240
($t:tt) => {
238241
compile_error!(concat!("unknown target feature: ", $t))
239242
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#![feature(stdsimd)]
2+
#![cfg_attr(stdsimd_strict, deny(warnings))]
3+
#![cfg_attr(
4+
feature = "cargo-clippy",
5+
allow(clippy::option_unwrap_used, clippy::use_debug, clippy::print_stdout)
6+
)]
7+
8+
#[cfg(any(
9+
target_arch = "arm",
10+
target_arch = "aarch64",
11+
target_arch = "x86",
12+
target_arch = "x86_64",
13+
target_arch = "powerpc",
14+
target_arch = "powerpc64"
15+
))]
16+
#[macro_use]
17+
extern crate std_detect;
18+
19+
#[test]
20+
#[cfg(all(target_arch = "arm", any(target_os = "linux", target_os = "android")))]
21+
fn arm_linux() {
22+
let _ = is_arm_feature_detected!("neon");
23+
let _ = is_arm_feature_detected!("neon",);
24+
}
25+
26+
#[test]
27+
#[cfg(all(
28+
target_arch = "aarch64",
29+
any(target_os = "linux", target_os = "android")
30+
))]
31+
fn aarch64_linux() {
32+
let _ = is_aarch64_feature_detected!("fp");
33+
let _ = is_aarch64_feature_detected!("fp",);
34+
}
35+
36+
#[test]
37+
#[cfg(all(target_arch = "powerpc", target_os = "linux"))]
38+
fn powerpc_linux() {
39+
let _ = is_powerpc_feature_detected!("altivec");
40+
let _ = is_powerpc_feature_detected!("altivec",);
41+
}
42+
43+
#[test]
44+
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
45+
fn powerpc64_linux() {
46+
let _ = is_powerpc64_feature_detected!("altivec");
47+
let _ = is_powerpc64_feature_detected!("altivec",);
48+
}
49+
50+
#[test]
51+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
52+
fn x86_all() {
53+
let _ = is_x86_feature_detected!("sse");
54+
let _ = is_x86_feature_detected!("sse",);
55+
}

0 commit comments

Comments
 (0)