diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e155a924990..3d9c8754991 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -133,7 +133,7 @@ impl EarlyProps { fn ignore_gdb(config: &Config, line: &str) -> bool { if let Some(actual_version) = config.gdb_version { if let Some(rest) = line.strip_prefix("min-gdb-version:").map(str::trim) { - let (start_ver, end_ver) = extract_gdb_version_range(rest); + let (start_ver, end_ver) = extract_version_range(rest, extract_gdb_version); if start_ver != end_ver { panic!("Expected single GDB version") @@ -142,7 +142,8 @@ impl EarlyProps { // version return actual_version < start_ver; } else if let Some(rest) = line.strip_prefix("ignore-gdb-version:").map(str::trim) { - let (min_version, max_version) = extract_gdb_version_range(rest); + let (min_version, max_version) = + extract_version_range(rest, extract_gdb_version); if max_version < min_version { panic!("Malformed GDB version range: max < min") @@ -154,36 +155,6 @@ impl EarlyProps { false } - // Takes a directive of the form " [- ]", - // returns the numeric representation of and as - // tuple: ( as u32, as u32) - // If the part is omitted, the second component of the tuple - // is the same as . - fn extract_gdb_version_range(line: &str) -> (u32, u32) { - const ERROR_MESSAGE: &'static str = "Malformed GDB version directive"; - - let range_components = line - .split(&[' ', '-'][..]) - .filter(|word| !word.is_empty()) - .map(extract_gdb_version) - .skip_while(Option::is_none) - .take(3) // 3 or more = invalid, so take at most 3. - .collect::>>(); - - match *range_components { - [v] => { - let v = v.unwrap(); - (v, v) - } - [min, max] => { - let v_min = min.unwrap(); - let v_max = max.expect(ERROR_MESSAGE); - (v_min, v_max) - } - _ => panic!(ERROR_MESSAGE), - } - } - fn ignore_lldb(config: &Config, line: &str) -> bool { if let Some(actual_version) = config.lldb_version { 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 { *line = &line[end + 1..]; Some(result) } + +// Takes a directive of the form " [- ]", +// returns the numeric representation of and as +// tuple: ( as u32, as u32) +// If the part is omitted, the second component of the tuple +// is the same as . +fn extract_version_range(line: &str, parse: F) -> (u32, u32) +where + F: Fn(&str) -> Option, +{ + let range_components = line + .split(&[' ', '-'][..]) + .filter(|word| !word.is_empty()) + .map(parse) + .skip_while(Option::is_none) + .take(3) // 3 or more = invalid, so take at most 3. + .collect::>>(); + + match *range_components { + [v] => { + let v = v.unwrap(); + (v, v) + } + [min, max] => { + let v_min = min.unwrap(); + let v_max = max.expect("Malformed version directive"); + (v_min, v_max) + } + _ => panic!("Malformed version directive"), + } +}