@@ -3486,10 +3486,12 @@ impl<'test> TestCx<'test> {
34863486 // with placeholders as we do not want tests needing updated when compiler source code
34873487 // changes.
34883488 // eg. $SRC_DIR/libcore/mem.rs:323:14 becomes $SRC_DIR/libcore/mem.rs:LL:COL
3489- normalized = Regex :: new ( "SRC_DIR(.+):\\ d+:\\ d+(: \\ d+:\\ d+)?" )
3490- . unwrap ( )
3491- . replace_all ( & normalized, "SRC_DIR$1:LL:COL" )
3492- . into_owned ( ) ;
3489+ lazy_static ! {
3490+ static ref SRC_DIR_RE : Regex =
3491+ Regex :: new( "SRC_DIR(.+):\\ d+:\\ d+(: \\ d+:\\ d+)?" ) . unwrap( ) ;
3492+ }
3493+
3494+ normalized = SRC_DIR_RE . replace_all ( & normalized, "SRC_DIR$1:LL:COL" ) . into_owned ( ) ;
34933495
34943496 normalized = Self :: normalize_platform_differences ( & normalized) ;
34953497 normalized = normalized. replace ( "\t " , "\\ t" ) ; // makes tabs visible
@@ -3498,38 +3500,37 @@ impl<'test> TestCx<'test> {
34983500 // since they duplicate actual errors and make the output hard to read.
34993501 // This mirrors the regex in src/tools/tidy/src/style.rs, please update
35003502 // both if either are changed.
3501- normalized =
3502- Regex :: new ( "\\ s*//(\\ [.*\\ ])?~.*" ) . unwrap ( ) . replace_all ( & normalized, "" ) . into_owned ( ) ;
3503+ lazy_static ! {
3504+ static ref ANNOTATION_RE : Regex = Regex :: new( "\\ s*//(\\ [.*\\ ])?~.*" ) . unwrap( ) ;
3505+ }
3506+
3507+ normalized = ANNOTATION_RE . replace_all ( & normalized, "" ) . into_owned ( ) ;
3508+
3509+ // This code normalizes various hashes in v0 symbol mangling that is
3510+ // emitted in the ui and mir-opt tests.
3511+ lazy_static ! {
3512+ static ref V0_CRATE_HASH_PREFIX_RE : Regex =
3513+ Regex :: new( r"_R.*?Cs[0-9a-zA-Z]+_" ) . unwrap( ) ;
3514+ static ref V0_CRATE_HASH_RE : Regex = Regex :: new( r"Cs[0-9a-zA-Z]+_" ) . unwrap( ) ;
3515+ }
35033516
3504- // This code normalizes various hashes in both
3505- // v0 and legacy symbol names that are emitted in
3506- // the ui and mir-opt tests.
3507- //
3508- // Some tests still require normalization with headers.
3509- const V0_CRATE_HASH_PREFIX_REGEX : & str = r"_R.*?Cs[0-9a-zA-Z]+_" ;
3510- const V0_CRATE_HASH_REGEX : & str = r"Cs[0-9a-zA-Z]+_" ;
35113517 const V0_CRATE_HASH_PLACEHOLDER : & str = r"CsCRATE_HASH_" ;
3512- const V0_BACK_REF_PREFIX_REGEX : & str = r"\(_R.*?B[0-9a-zA-Z]_" ;
3513- const V0_BACK_REF_REGEX : & str = r"B[0-9a-zA-Z]_" ;
3514- const V0_BACK_REF_PLACEHOLDER : & str = r"B<REF>_" ;
3515- // Normalize v0 crate hashes (see RFC 2603)
3516- let symbol_mangle_prefix_re = Regex :: new ( V0_CRATE_HASH_PREFIX_REGEX ) . unwrap ( ) ;
3517- if symbol_mangle_prefix_re. is_match ( & normalized) {
3518+ if V0_CRATE_HASH_PREFIX_RE . is_match ( & normalized) {
35183519 // Normalize crate hash
3519- normalized = Regex :: new ( V0_CRATE_HASH_REGEX )
3520- . unwrap ( )
3521- . replace_all ( & normalized, V0_CRATE_HASH_PLACEHOLDER )
3522- . into_owned ( ) ;
3520+ normalized =
3521+ V0_CRATE_HASH_RE . replace_all ( & normalized, V0_CRATE_HASH_PLACEHOLDER ) . into_owned ( ) ;
35233522 }
3524- let back_ref_prefix_re = Regex :: new ( V0_BACK_REF_PREFIX_REGEX ) . unwrap ( ) ;
3525- if back_ref_prefix_re. is_match ( & normalized) {
3523+
3524+ lazy_static ! {
3525+ static ref V0_BACK_REF_PREFIX_RE : Regex = Regex :: new( r"\(_R.*?B[0-9a-zA-Z]_" ) . unwrap( ) ;
3526+ static ref V0_BACK_REF_RE : Regex = Regex :: new( r"B[0-9a-zA-Z]_" ) . unwrap( ) ;
3527+ }
3528+
3529+ const V0_BACK_REF_PLACEHOLDER : & str = r"B<REF>_" ;
3530+ if V0_BACK_REF_PREFIX_RE . is_match ( & normalized) {
35263531 // Normalize back references (see RFC 2603)
3527- let back_ref_regex = format ! ( "{}" , V0_BACK_REF_REGEX ) ;
3528- let back_ref_placeholder = format ! ( "{}" , V0_BACK_REF_PLACEHOLDER ) ;
3529- normalized = Regex :: new ( & back_ref_regex)
3530- . unwrap ( )
3531- . replace_all ( & normalized, back_ref_placeholder)
3532- . into_owned ( ) ;
3532+ normalized =
3533+ V0_BACK_REF_RE . replace_all ( & normalized, V0_BACK_REF_PLACEHOLDER ) . into_owned ( ) ;
35333534 }
35343535
35353536 // Custom normalization rules
0 commit comments