Skip to content

Commit ec14730

Browse files
committed
Test cfg_match! support
1 parent 5c92d8f commit ec14730

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5403
-0
lines changed

src/test/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const FILE_SKIP_LIST: &[&str] = &[
3939
// These files and directory are a part of modules defined inside `cfg_if!`.
4040
"cfg_if/mod.rs",
4141
"cfg_if/detect",
42+
"cfg_match/mod.rs",
43+
"cfg_match/detect",
4244
"issue-3253/foo.rs",
4345
"issue-3253/bar.rs",
4446
"issue-3253/paths",
@@ -468,6 +470,44 @@ fn format_files_find_new_files_via_cfg_if() {
468470
});
469471
}
470472

473+
#[test]
474+
fn format_files_find_new_files_via_cfg_match() {
475+
init_log();
476+
run_test_with(&TestSetting::default(), || {
477+
// To repro issue-4656, it is necessary that these files are parsed
478+
// as a part of the same session (hence this separate test runner).
479+
let files = vec![
480+
Path::new("tests/source/issue-4656-match/lib2.rs"),
481+
Path::new("tests/source/issue-4656-match/lib.rs"),
482+
];
483+
484+
let config = Config::default();
485+
let mut session = Session::<io::Stdout>::new(config, None);
486+
487+
let mut write_result = HashMap::new();
488+
for file in files {
489+
assert!(file.exists());
490+
let result = session.format(Input::File(file.into())).unwrap();
491+
assert!(!session.has_formatting_errors());
492+
assert!(!result.has_warnings());
493+
let mut source_file = SourceFile::new();
494+
mem::swap(&mut session.source_file, &mut source_file);
495+
496+
for (filename, text) in source_file {
497+
if let FileName::Real(ref filename) = filename {
498+
write_result.insert(filename.to_owned(), text);
499+
}
500+
}
501+
}
502+
assert_eq!(
503+
3,
504+
write_result.len(),
505+
"Should have uncovered an extra file (format_me_please.rs) via lib.rs"
506+
);
507+
assert!(handle_result(write_result, None).is_ok());
508+
});
509+
}
510+
471511
#[test]
472512
fn stdin_formatting_smoke_test() {
473513
init_log();
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//! Aarch64 run-time features.
2+
3+
/// Checks if `aarch64` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_aarch64_feature_detected {
8+
("neon") => {
9+
// FIXME: this should be removed once we rename Aarch64 neon to asimd
10+
cfg!(target_feature = "neon") ||
11+
$crate::detect::check_for($crate::detect::Feature::asimd)
12+
};
13+
("asimd") => {
14+
cfg!(target_feature = "neon") ||
15+
$crate::detect::check_for($crate::detect::Feature::asimd)
16+
};
17+
("pmull") => {
18+
cfg!(target_feature = "pmull") ||
19+
$crate::detect::check_for($crate::detect::Feature::pmull)
20+
};
21+
("fp") => {
22+
cfg!(target_feature = "fp") ||
23+
$crate::detect::check_for($crate::detect::Feature::fp)
24+
};
25+
("fp16") => {
26+
cfg!(target_feature = "fp16") ||
27+
$crate::detect::check_for($crate::detect::Feature::fp16)
28+
};
29+
("sve") => {
30+
cfg!(target_feature = "sve") ||
31+
$crate::detect::check_for($crate::detect::Feature::sve)
32+
};
33+
("crc") => {
34+
cfg!(target_feature = "crc") ||
35+
$crate::detect::check_for($crate::detect::Feature::crc)
36+
};
37+
("crypto") => {
38+
cfg!(target_feature = "crypto") ||
39+
$crate::detect::check_for($crate::detect::Feature::crypto)
40+
};
41+
("lse") => {
42+
cfg!(target_feature = "lse") ||
43+
$crate::detect::check_for($crate::detect::Feature::lse)
44+
};
45+
("rdm") => {
46+
cfg!(target_feature = "rdm") ||
47+
$crate::detect::check_for($crate::detect::Feature::rdm)
48+
};
49+
("rcpc") => {
50+
cfg!(target_feature = "rcpc") ||
51+
$crate::detect::check_for($crate::detect::Feature::rcpc)
52+
};
53+
("dotprod") => {
54+
cfg!(target_feature = "dotprod") ||
55+
$crate::detect::check_for($crate::detect::Feature::dotprod)
56+
};
57+
("ras") => {
58+
compile_error!("\"ras\" feature cannot be detected at run-time")
59+
};
60+
("v8.1a") => {
61+
compile_error!("\"v8.1a\" feature cannot be detected at run-time")
62+
};
63+
("v8.2a") => {
64+
compile_error!("\"v8.2a\" feature cannot be detected at run-time")
65+
};
66+
("v8.3a") => {
67+
compile_error!("\"v8.3a\" feature cannot be detected at run-time")
68+
};
69+
($t:tt,) => {
70+
is_aarch64_feature_detected!($t);
71+
};
72+
($t:tt) => { compile_error!(concat!("unknown aarch64 target feature: ", $t)) };
73+
}
74+
75+
/// ARM Aarch64 CPU Feature enum. Each variant denotes a position in a bitset
76+
/// for a particular feature.
77+
///
78+
/// PLEASE: do not use this, it is an implementation detail subject to change.
79+
#[doc(hidden)]
80+
#[allow(non_camel_case_types)]
81+
#[repr(u8)]
82+
#[unstable(feature = "stdsimd_internal", issue = "0")]
83+
pub enum Feature {
84+
/// ARM Advanced SIMD (ASIMD)
85+
asimd,
86+
/// Polynomial Multiply
87+
pmull,
88+
/// Floating point support
89+
fp,
90+
/// Half-float support.
91+
fp16,
92+
/// Scalable Vector Extension (SVE)
93+
sve,
94+
/// CRC32 (Cyclic Redundancy Check)
95+
crc,
96+
/// Crypto: AES + PMULL + SHA1 + SHA2
97+
crypto,
98+
/// Atomics (Large System Extension)
99+
lse,
100+
/// Rounding Double Multiply (ASIMDRDM)
101+
rdm,
102+
/// Release consistent Processor consistent (RcPc)
103+
rcpc,
104+
/// Vector Dot-Product (ASIMDDP)
105+
dotprod,
106+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Run-time feature detection on ARM Aarch32.
2+
3+
/// Checks if `arm` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_arm_feature_detected {
8+
("neon") => {
9+
cfg!(target_feature = "neon") ||
10+
$crate::detect::check_for($crate::detect::Feature::neon)
11+
};
12+
("pmull") => {
13+
cfg!(target_feature = "pmull") ||
14+
$crate::detect::check_for($crate::detect::Feature::pmull)
15+
};
16+
("v7") => { compile_error!("\"v7\" feature cannot be detected at run-time") };
17+
("vfp2") => { compile_error!("\"vfp2\" feature cannot be detected at run-time") };
18+
("vfp3") => { compile_error!("\"vfp3\" feature cannot be detected at run-time") };
19+
("vfp4") => { compile_error!("\"vfp4\" feature cannot be detected at run-time") };
20+
($t:tt,) => {
21+
is_arm_feature_detected!($t);
22+
};
23+
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
24+
}
25+
26+
/// ARM CPU Feature enum. Each variant denotes a position in a bitset for a
27+
/// particular feature.
28+
///
29+
/// PLEASE: do not use this, it is an implementation detail subject to change.
30+
#[doc(hidden)]
31+
#[allow(non_camel_case_types)]
32+
#[repr(u8)]
33+
#[unstable(feature = "stdsimd_internal", issue = "0")]
34+
pub enum Feature {
35+
/// ARM Advanced SIMD (NEON) - Aarch32
36+
neon,
37+
/// Polynomial Multiply
38+
pmull,
39+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Run-time feature detection on MIPS.
2+
3+
/// Checks if `mips` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_mips_feature_detected {
8+
("msa") => {
9+
cfg!(target_feature = "msa") ||
10+
$crate::detect::check_for($crate::detect::Feature::msa)
11+
};
12+
($t:tt,) => {
13+
is_mips_feature_detected!($t);
14+
};
15+
($t:tt) => { compile_error!(concat!("unknown mips target feature: ", $t)) };
16+
}
17+
18+
/// MIPS CPU Feature enum. Each variant denotes a position in a bitset for a
19+
/// particular feature.
20+
///
21+
/// PLEASE: do not use this, it is an implementation detail subject to change.
22+
#[doc(hidden)]
23+
#[allow(non_camel_case_types)]
24+
#[repr(u8)]
25+
#[unstable(feature = "stdsimd_internal", issue = "0")]
26+
pub enum Feature {
27+
/// MIPS SIMD Architecture (MSA)
28+
msa,
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Run-time feature detection on MIPS64.
2+
3+
/// Checks if `mips64` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_mips64_feature_detected {
8+
("msa") => {
9+
cfg!(target_feature = "msa") ||
10+
$crate::detect::check_for($crate::detect::Feature::msa)
11+
};
12+
($t:tt,) => {
13+
is_mips64_feature_detected!($t);
14+
};
15+
($t:tt) => { compile_error!(concat!("unknown mips64 target feature: ", $t)) };
16+
}
17+
18+
/// MIPS64 CPU Feature enum. Each variant denotes a position in a bitset
19+
/// for a particular feature.
20+
///
21+
/// PLEASE: do not use this, it is an implementation detail subject to change.
22+
#[doc(hidden)]
23+
#[allow(non_camel_case_types)]
24+
#[repr(u8)]
25+
#[unstable(feature = "stdsimd_internal", issue = "0")]
26+
pub enum Feature {
27+
/// MIPS SIMD Architecture (MSA)
28+
msa,
29+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Run-time feature detection on PowerPC.
2+
3+
/// Checks if `powerpc` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_powerpc_feature_detected {
8+
("altivec") => {
9+
cfg!(target_feature = "altivec") ||
10+
$crate::detect::check_for($crate::detect::Feature::altivec)
11+
};
12+
("vsx") => {
13+
cfg!(target_feature = "vsx") ||
14+
$crate::detect::check_for($crate::detect::Feature::vsx)
15+
};
16+
("power8") => {
17+
cfg!(target_feature = "power8") ||
18+
$crate::detect::check_for($crate::detect::Feature::power8)
19+
};
20+
($t:tt,) => {
21+
is_powerpc_feature_detected!($t);
22+
};
23+
($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) };
24+
}
25+
26+
27+
/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
28+
/// for a particular feature.
29+
///
30+
/// PLEASE: do not use this, it is an implementation detail subject to change.
31+
#[doc(hidden)]
32+
#[allow(non_camel_case_types)]
33+
#[repr(u8)]
34+
#[unstable(feature = "stdsimd_internal", issue = "0")]
35+
pub enum Feature {
36+
/// Altivec
37+
altivec,
38+
/// VSX
39+
vsx,
40+
/// Power8
41+
power8,
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Run-time feature detection on PowerPC64.
2+
3+
/// Checks if `powerpc64` feature is enabled.
4+
#[macro_export]
5+
#[unstable(feature = "stdsimd", issue = "27731")]
6+
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7+
macro_rules! is_powerpc64_feature_detected {
8+
("altivec") => {
9+
cfg!(target_feature = "altivec") ||
10+
$crate::detect::check_for($crate::detect::Feature::altivec)
11+
};
12+
("vsx") => {
13+
cfg!(target_feature = "vsx") ||
14+
$crate::detect::check_for($crate::detect::Feature::vsx)
15+
};
16+
("power8") => {
17+
cfg!(target_feature = "power8") ||
18+
$crate::detect::check_for($crate::detect::Feature::power8)
19+
};
20+
($t:tt,) => {
21+
is_powerpc64_feature_detected!($t);
22+
};
23+
($t:tt) => { compile_error!(concat!("unknown powerpc64 target feature: ", $t)) };
24+
}
25+
26+
27+
/// PowerPC64 CPU Feature enum. Each variant denotes a position in a bitset
28+
/// for a particular feature.
29+
///
30+
/// PLEASE: do not use this, it is an implementation detail subject to change.
31+
#[doc(hidden)]
32+
#[allow(non_camel_case_types)]
33+
#[repr(u8)]
34+
#[unstable(feature = "stdsimd_internal", issue = "0")]
35+
pub enum Feature {
36+
/// Altivec
37+
altivec,
38+
/// VSX
39+
vsx,
40+
/// Power8
41+
power8,
42+
}

0 commit comments

Comments
 (0)