Skip to content

Commit 99e3a3c

Browse files
committed
Extract extract_version_range
1 parent 2bcefa8 commit 99e3a3c

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/tools/compiletest/src/header.rs

+34-32
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl EarlyProps {
133133
fn ignore_gdb(config: &Config, line: &str) -> bool {
134134
if let Some(actual_version) = config.gdb_version {
135135
if let Some(rest) = line.strip_prefix("min-gdb-version:").map(str::trim) {
136-
let (start_ver, end_ver) = extract_gdb_version_range(rest);
136+
let (start_ver, end_ver) = extract_version_range(rest, extract_gdb_version);
137137

138138
if start_ver != end_ver {
139139
panic!("Expected single GDB version")
@@ -142,7 +142,8 @@ impl EarlyProps {
142142
// version
143143
return actual_version < start_ver;
144144
} else if let Some(rest) = line.strip_prefix("ignore-gdb-version:").map(str::trim) {
145-
let (min_version, max_version) = extract_gdb_version_range(rest);
145+
let (min_version, max_version) =
146+
extract_version_range(rest, extract_gdb_version);
146147

147148
if max_version < min_version {
148149
panic!("Malformed GDB version range: max < min")
@@ -154,36 +155,6 @@ impl EarlyProps {
154155
false
155156
}
156157

157-
// Takes a directive of the form "<version1> [- <version2>]",
158-
// returns the numeric representation of <version1> and <version2> as
159-
// tuple: (<version1> as u32, <version2> as u32)
160-
// If the <version2> part is omitted, the second component of the tuple
161-
// is the same as <version1>.
162-
fn extract_gdb_version_range(line: &str) -> (u32, u32) {
163-
const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
164-
165-
let range_components = line
166-
.split(&[' ', '-'][..])
167-
.filter(|word| !word.is_empty())
168-
.map(extract_gdb_version)
169-
.skip_while(Option::is_none)
170-
.take(3) // 3 or more = invalid, so take at most 3.
171-
.collect::<Vec<Option<u32>>>();
172-
173-
match *range_components {
174-
[v] => {
175-
let v = v.unwrap();
176-
(v, v)
177-
}
178-
[min, max] => {
179-
let v_min = min.unwrap();
180-
let v_max = max.expect(ERROR_MESSAGE);
181-
(v_min, v_max)
182-
}
183-
_ => panic!(ERROR_MESSAGE),
184-
}
185-
}
186-
187158
fn ignore_lldb(config: &Config, line: &str) -> bool {
188159
if let Some(actual_version) = config.lldb_version {
189160
if let Some(min_version) = line.strip_prefix("min-lldb-version:").map(str::trim) {
@@ -982,3 +953,34 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
982953
*line = &line[end + 1..];
983954
Some(result)
984955
}
956+
957+
// Takes a directive of the form "<version1> [- <version2>]",
958+
// returns the numeric representation of <version1> and <version2> as
959+
// tuple: (<version1> as u32, <version2> as u32)
960+
// If the <version2> part is omitted, the second component of the tuple
961+
// is the same as <version1>.
962+
fn extract_version_range<F>(line: &str, parse: F) -> (u32, u32)
963+
where
964+
F: Fn(&str) -> Option<u32>,
965+
{
966+
let range_components = line
967+
.split(&[' ', '-'][..])
968+
.filter(|word| !word.is_empty())
969+
.map(parse)
970+
.skip_while(Option::is_none)
971+
.take(3) // 3 or more = invalid, so take at most 3.
972+
.collect::<Vec<Option<u32>>>();
973+
974+
match *range_components {
975+
[v] => {
976+
let v = v.unwrap();
977+
(v, v)
978+
}
979+
[min, max] => {
980+
let v_min = min.unwrap();
981+
let v_max = max.expect("Malformed version directive");
982+
(v_min, v_max)
983+
}
984+
_ => panic!("Malformed version directive"),
985+
}
986+
}

0 commit comments

Comments
 (0)