diff --git a/Cargo.lock b/Cargo.lock index 1963f7c0d5662..7c6c10cdbd726 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2541,9 +2541,6 @@ dependencies = [ [[package]] name = "miropt-test-tools" version = "0.1.0" -dependencies = [ - "regex", -] [[package]] name = "native-tls" diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 4ceb8a646e060..117828645a94f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -6,6 +6,7 @@ use std::io::BufReader; use std::path::{Path, PathBuf}; use std::process::Command; +use once_cell::sync::Lazy; use regex::Regex; use tracing::*; @@ -829,7 +830,8 @@ fn iter_header_extra( let mut ln = String::new(); let mut line_number = 0; - let revision_magic_comment = Regex::new("//(\\[.*\\])?~.*").unwrap(); + static REVISION_MAGIC_COMMENT_RE: Lazy = + Lazy::new(|| Regex::new("//(\\[.*\\])?~.*").unwrap()); loop { line_number += 1; @@ -849,7 +851,7 @@ fn iter_header_extra( // First try to accept `ui_test` style comments } else if let Some((lncfg, ln)) = line_directive(comment, ln) { it(lncfg, orig_ln, ln, line_number); - } else if mode == Mode::Ui && suite == "ui" && !revision_magic_comment.is_match(ln) { + } else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) { let Some((_, rest)) = line_directive("//", ln) else { continue; }; diff --git a/src/tools/miropt-test-tools/Cargo.toml b/src/tools/miropt-test-tools/Cargo.toml index 8589a44cf1bab..09b4c7d16dce3 100644 --- a/src/tools/miropt-test-tools/Cargo.toml +++ b/src/tools/miropt-test-tools/Cargo.toml @@ -4,4 +4,3 @@ version = "0.1.0" edition = "2021" [dependencies] -regex = "1.0" diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs index 7d60033c3e824..4317f23a82219 100644 --- a/src/tools/miropt-test-tools/src/lib.rs +++ b/src/tools/miropt-test-tools/src/lib.rs @@ -100,14 +100,19 @@ pub fn files_for_miropt_test( } else { // Allow-list for file extensions that can be produced by MIR dumps. // Other extensions can be added here, as needed by new dump flags. - let ext_re = regex::Regex::new(r#"(\.(mir|dot))$"#).unwrap(); - let cap = ext_re.captures_iter(test_name).next().unwrap_or_else(|| { - panic!("in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}") - }); - let extension = cap.get(1).unwrap().as_str(); + static ALLOWED_EXT: &[&str] = &["mir", "dot"]; + let Some((test_name_wo_ext, test_name_ext)) = test_name.rsplit_once('.') else { + panic!( + "in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}" + ) + }; + if !ALLOWED_EXT.contains(&test_name_ext) { + panic!( + "in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}" + ) + } - expected_file = - format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,); + expected_file = format!("{}{}.{}", test_name_wo_ext, suffix, test_name_ext); from_file = test_name.to_string(); assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump"); to_file = None; diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index a8aae6f5bc9d3..28d70b4454cee 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -130,16 +130,20 @@ fn should_ignore(line: &str) -> bool { // Matches test annotations like `//~ ERROR text`. // This mirrors the regex in src/tools/compiletest/src/runtest.rs, please // update both if either are changed. - let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap(); + lazy_static::lazy_static! { + static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap(); + } // For `ui_test`-style UI test directives, also ignore // - `//@[rev] compile-flags` // - `//@[rev] normalize-stderr-test` - let ui_test_long_directives = + lazy_static::lazy_static! { + static ref UI_TEST_LONG_DIRECTIVES_RE: Regex = Regex::new("\\s*//@(\\[.*\\]) (compile-flags|normalize-stderr-test|error-pattern).*") .unwrap(); - re.is_match(line) + } + ANNOTATION_RE.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a)) - || ui_test_long_directives.is_match(line) + || UI_TEST_LONG_DIRECTIVES_RE.is_match(line) } /// Returns `true` if `line` is allowed to be longer than the normal limit.