Skip to content

Commit 1cd2da6

Browse files
committed
Move get_pointer_width to a method on Config
1 parent 04e5230 commit 1cd2da6

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/config.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,28 @@ impl Config {
281281
.any(|arch| self.target.as_ref().unwrap().contains(arch))
282282
}
283283

284+
pub(crate) fn get_pointer_width(&self) -> u8 {
285+
// Taken 1:1 from compiletest-rs
286+
fn get_pointer_width(triple: &str) -> u8 {
287+
if (triple.contains("64")
288+
&& !triple.ends_with("gnux32")
289+
&& !triple.ends_with("gnu_ilp32"))
290+
|| triple.starts_with("s390x")
291+
{
292+
64
293+
} else if triple.starts_with("avr") {
294+
16
295+
} else {
296+
32
297+
}
298+
}
299+
get_pointer_width(self.target.as_ref().unwrap())
300+
}
301+
284302
pub(crate) fn test_condition(&self, condition: &Condition) -> bool {
285303
let target = self.target.as_ref().unwrap();
286304
match condition {
287-
Condition::Bitwidth(bits) => crate::get_pointer_width(target) == *bits,
305+
Condition::Bitwidth(bits) => self.get_pointer_width() == *bits,
288306
Condition::Target(t) => target.contains(t),
289307
Condition::Host(t) => self.host.as_ref().unwrap().contains(t),
290308
Condition::OnHost => self.host_matches_target(),

src/lib.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,8 @@ fn check_output(
10541054
kind: &'static str,
10551055
config: &TestConfig,
10561056
) -> PathBuf {
1057-
let target = config.config.target.as_ref().unwrap();
10581057
let output = normalize(output, config.comments, config.revision, kind);
1059-
let path = output_path(config, revised(config.revision, kind), target);
1058+
let path = output_path(config, revised(config.revision, kind));
10601059
match &config.config.output_conflict_handling {
10611060
OutputConflictHandling::Error => {
10621061
let expected_output = std::fs::read(&path).unwrap_or_default();
@@ -1081,28 +1080,15 @@ fn check_output(
10811080
path
10821081
}
10831082

1084-
fn output_path(config: &TestConfig<'_>, kind: String, target: &str) -> PathBuf {
1083+
fn output_path(config: &TestConfig<'_>, kind: String) -> PathBuf {
10851084
if config.comments().any(|r| r.stderr_per_bitwidth) {
10861085
return config
10871086
.path
1088-
.with_extension(format!("{}bit.{kind}", get_pointer_width(target)));
1087+
.with_extension(format!("{}bit.{kind}", config.config.get_pointer_width()));
10891088
}
10901089
config.path.with_extension(kind)
10911090
}
10921091

1093-
// Taken 1:1 from compiletest-rs
1094-
fn get_pointer_width(triple: &str) -> u8 {
1095-
if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
1096-
|| triple.starts_with("s390x")
1097-
{
1098-
64
1099-
} else if triple.starts_with("avr") {
1100-
16
1101-
} else {
1102-
32
1103-
}
1104-
}
1105-
11061092
fn normalize(text: &[u8], comments: &Comments, revision: &str, kind: &'static str) -> Vec<u8> {
11071093
let mut text = text.to_owned();
11081094

0 commit comments

Comments
 (0)