mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
replace lazy_static with once_cell
This commit is contained in:
parent
1397a5ef92
commit
58e7470b10
@ -891,11 +891,11 @@ dependencies = [
|
||||
"diff",
|
||||
"getopts",
|
||||
"glob",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"libc",
|
||||
"miow 0.5.0",
|
||||
"miropt-test-tools",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"rustfix",
|
||||
"serde",
|
||||
|
@ -16,7 +16,7 @@ regex = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
rustfix = "0.6.0"
|
||||
lazy_static = "1.0"
|
||||
once_cell = "1.16.0"
|
||||
walkdir = "2"
|
||||
glob = "0.3.0"
|
||||
lazycell = "1.3.0"
|
||||
|
@ -7,7 +7,7 @@ use std::io::BufReader;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use tracing::*;
|
||||
|
||||
@ -117,10 +117,8 @@ fn parse_expected(
|
||||
// //~^^^^^
|
||||
// //[cfg1]~
|
||||
// //[cfg1,cfg2]~^^
|
||||
lazy_static! {
|
||||
static ref RE: Regex =
|
||||
Regex::new(r"//(?:\[(?P<cfgs>[\w,]+)])?~(?P<adjust>\||\^*)").unwrap();
|
||||
}
|
||||
static RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"//(?:\[(?P<cfgs>[\w,]+)])?~(?P<adjust>\||\^*)").unwrap());
|
||||
|
||||
let captures = RE.captures(line)?;
|
||||
|
||||
|
@ -32,7 +32,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio};
|
||||
use std::str;
|
||||
|
||||
use glob::glob;
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use tracing::*;
|
||||
|
||||
use crate::extract_gdb_version;
|
||||
@ -52,9 +52,8 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
use winapi::um::errhandlingapi::SetErrorMode;
|
||||
use winapi::um::winbase::SEM_NOGPFAULTERRORBOX;
|
||||
|
||||
lazy_static! {
|
||||
static ref LOCK: Mutex<()> = Mutex::new(());
|
||||
}
|
||||
static LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
// Error mode is a global variable, so lock it so only one thread will change it
|
||||
let _lock = LOCK.lock().unwrap();
|
||||
|
||||
@ -2848,11 +2847,10 @@ impl<'test> TestCx<'test> {
|
||||
// the form <crate-name1>.<crate-disambiguator1>-in-<crate-name2>.<crate-disambiguator2>,
|
||||
// remove all crate-disambiguators.
|
||||
fn remove_crate_disambiguator_from_cgu(cgu: &str) -> String {
|
||||
lazy_static! {
|
||||
static ref RE: Regex =
|
||||
static RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"^[^\.]+(?P<d1>\.[[:alnum:]]+)(-in-[^\.]+(?P<d2>\.[[:alnum:]]+))?")
|
||||
.unwrap();
|
||||
}
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let captures =
|
||||
RE.captures(cgu).unwrap_or_else(|| panic!("invalid cgu name encountered: {}", cgu));
|
||||
@ -3170,12 +3168,12 @@ impl<'test> TestCx<'test> {
|
||||
// 'uploaded "$TEST_BUILD_DIR/<test_executable>, waiting for result"'
|
||||
// is printed to stdout by the client and then captured in the ProcRes,
|
||||
// so it needs to be removed when comparing the run-pass test execution output
|
||||
lazy_static! {
|
||||
static ref REMOTE_TEST_RE: Regex = Regex::new(
|
||||
static REMOTE_TEST_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(
|
||||
"^uploaded \"\\$TEST_BUILD_DIR(/[[:alnum:]_\\-.]+)+\", waiting for result\n"
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
.unwrap()
|
||||
});
|
||||
REMOTE_TEST_RE
|
||||
.replace(
|
||||
&self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout),
|
||||
@ -3620,10 +3618,8 @@ impl<'test> TestCx<'test> {
|
||||
// with placeholders as we do not want tests needing updated when compiler source code
|
||||
// changes.
|
||||
// eg. $SRC_DIR/libcore/mem.rs:323:14 becomes $SRC_DIR/libcore/mem.rs:LL:COL
|
||||
lazy_static! {
|
||||
static ref SRC_DIR_RE: Regex =
|
||||
Regex::new("SRC_DIR(.+):\\d+:\\d+(: \\d+:\\d+)?").unwrap();
|
||||
}
|
||||
static SRC_DIR_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("SRC_DIR(.+):\\d+:\\d+(: \\d+:\\d+)?").unwrap());
|
||||
|
||||
normalized = SRC_DIR_RE.replace_all(&normalized, "SRC_DIR$1:LL:COL").into_owned();
|
||||
|
||||
@ -3634,19 +3630,17 @@ impl<'test> TestCx<'test> {
|
||||
// since they duplicate actual errors and make the output hard to read.
|
||||
// This mirrors the regex in src/tools/tidy/src/style.rs, please update
|
||||
// both if either are changed.
|
||||
lazy_static! {
|
||||
static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
|
||||
}
|
||||
static ANNOTATION_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("\\s*//(\\[.*\\])?~.*").unwrap());
|
||||
|
||||
normalized = ANNOTATION_RE.replace_all(&normalized, "").into_owned();
|
||||
|
||||
// This code normalizes various hashes in v0 symbol mangling that is
|
||||
// emitted in the ui and mir-opt tests.
|
||||
lazy_static! {
|
||||
static ref V0_CRATE_HASH_PREFIX_RE: Regex =
|
||||
Regex::new(r"_R.*?Cs[0-9a-zA-Z]+_").unwrap();
|
||||
static ref V0_CRATE_HASH_RE: Regex = Regex::new(r"Cs[0-9a-zA-Z]+_").unwrap();
|
||||
}
|
||||
static V0_CRATE_HASH_PREFIX_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"_R.*?Cs[0-9a-zA-Z]+_").unwrap());
|
||||
static V0_CRATE_HASH_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"Cs[0-9a-zA-Z]+_").unwrap());
|
||||
|
||||
const V0_CRATE_HASH_PLACEHOLDER: &str = r"CsCRATE_HASH_";
|
||||
if V0_CRATE_HASH_PREFIX_RE.is_match(&normalized) {
|
||||
@ -3655,10 +3649,9 @@ impl<'test> TestCx<'test> {
|
||||
V0_CRATE_HASH_RE.replace_all(&normalized, V0_CRATE_HASH_PLACEHOLDER).into_owned();
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref V0_BACK_REF_PREFIX_RE: Regex = Regex::new(r"\(_R.*?B[0-9a-zA-Z]_").unwrap();
|
||||
static ref V0_BACK_REF_RE: Regex = Regex::new(r"B[0-9a-zA-Z]_").unwrap();
|
||||
}
|
||||
static V0_BACK_REF_PREFIX_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"\(_R.*?B[0-9a-zA-Z]_").unwrap());
|
||||
static V0_BACK_REF_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"B[0-9a-zA-Z]_").unwrap());
|
||||
|
||||
const V0_BACK_REF_PLACEHOLDER: &str = r"B<REF>_";
|
||||
if V0_BACK_REF_PREFIX_RE.is_match(&normalized) {
|
||||
@ -3681,21 +3674,23 @@ impl<'test> TestCx<'test> {
|
||||
/// Replaces backslashes in paths with forward slashes, and replaces CRLF line endings
|
||||
/// with LF.
|
||||
fn normalize_platform_differences(output: &str) -> String {
|
||||
lazy_static! {
|
||||
/// Used to find Windows paths.
|
||||
///
|
||||
/// It's not possible to detect paths in the error messages generally, but this is a
|
||||
/// decent enough heuristic.
|
||||
static ref PATH_BACKSLASH_RE: Regex = Regex::new(r#"(?x)
|
||||
static PATH_BACKSLASH_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(
|
||||
r#"(?x)
|
||||
(?:
|
||||
# Match paths that don't include spaces.
|
||||
(?:\\[\pL\pN\.\-_']+)+\.\pL+
|
||||
|
|
||||
# If the path starts with a well-known root, then allow spaces.
|
||||
\$(?:DIR|SRC_DIR|TEST_BUILD_DIR|BUILD_DIR|LIB_DIR)(?:\\[\pL\pN\.\-_' ]+)+
|
||||
)"#
|
||||
).unwrap();
|
||||
}
|
||||
)"#,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let output = output.replace(r"\\", r"\");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user