@@ -3486,10 +3486,12 @@ impl<'test> TestCx<'test> {
3486
3486
// with placeholders as we do not want tests needing updated when compiler source code
3487
3487
// changes.
3488
3488
// 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 ( ) ;
3493
3495
3494
3496
normalized = Self :: normalize_platform_differences ( & normalized) ;
3495
3497
normalized = normalized. replace ( "\t " , "\\ t" ) ; // makes tabs visible
@@ -3498,38 +3500,37 @@ impl<'test> TestCx<'test> {
3498
3500
// since they duplicate actual errors and make the output hard to read.
3499
3501
// This mirrors the regex in src/tools/tidy/src/style.rs, please update
3500
3502
// 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
+ }
3503
3516
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]+_" ;
3511
3517
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) {
3518
3519
// 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 ( ) ;
3523
3522
}
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) {
3526
3531
// 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 ( ) ;
3533
3534
}
3534
3535
3535
3536
// Custom normalization rules
0 commit comments