Skip to content

Commit 411e580

Browse files
authored
Merge pull request #546 from serprex/remove-lazy-static
replace lazy_static with std::sync::LazyLock
2 parents 4b78455 + a54d0a9 commit 411e580

File tree

5 files changed

+30
-45
lines changed

5 files changed

+30
-45
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ compiletest_rs = "0.11"
1717
convert_case = "0.6"
1818
criterion = "0.5"
1919
insta = "1"
20-
lazy_static = "1.2"
2120
message-io = { version = "0.19.0", default-features = false, features = [
2221
"tcp",
2322
"udp",

proptest/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ attr-macro = ["proptest-macro"]
2929
unstable = []
3030

3131
# Enables the use of standard-library dependent features
32-
std = ["rand/std", "rand/os_rng", "lazy_static", "regex-syntax", "num-traits/std"]
32+
std = ["rand/std", "rand/os_rng", "regex-syntax", "num-traits/std"]
3333

3434
# std or libm required for mul_add.
3535
no_std = ["num-traits/libm"]
@@ -66,7 +66,6 @@ handle-panics = ["std"]
6666
bitflags = { workspace = true }
6767
unarray = { workspace = true }
6868
proptest-macro = { workspace = true, optional = true }
69-
lazy_static = { workspace = true, optional = true }
7069
num-traits = { workspace = true }
7170
regex-syntax = { workspace = true, optional = true }
7271
bit-set = { workspace = true, optional = true }

proptest/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ extern crate bitflags;
5050
#[cfg(feature = "bit-set")]
5151
extern crate bit_set;
5252

53-
#[cfg(feature = "std")]
54-
#[macro_use]
55-
extern crate lazy_static;
56-
5753
#[cfg(feature = "fork")]
5854
#[macro_use]
5955
extern crate rusty_fork;

proptest/src/test_runner/config.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,11 @@ fn default_default_config() -> Config {
188188
// The default config, computed by combining environment variables and
189189
// defaults.
190190
#[cfg(feature = "std")]
191-
lazy_static! {
192-
static ref DEFAULT_CONFIG: Config = {
193-
let mut default_config = default_default_config();
194-
default_config.failure_persistence = Some(Box::new(crate::test_runner::FileFailurePersistence::default()));
195-
contextualize_config(default_config)
196-
};
197-
}
191+
static DEFAULT_CONFIG: std::sync::LazyLock<Config> = std::sync::LazyLock::new(|| {
192+
let mut default_config = default_default_config();
193+
default_config.failure_persistence = Some(Box::new(crate::test_runner::FileFailurePersistence::default()));
194+
contextualize_config(default_config)
195+
});
198196

199197
/// The seed for the RNG, can either be random or specified as a u64.
200198
#[derive(Debug, Clone, Copy, PartialEq)]

proptest/src/test_runner/failure_persistence/file.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,13 @@ impl FileFailurePersistence {
402402
}
403403
}
404404

405-
lazy_static! {
406-
/// Used to guard access to the persistence file(s) so that a single
407-
/// process will not step on its own toes.
408-
///
409-
/// We don't have much protecting us should two separate process try to
410-
/// write to the same file at once (depending on how atomic append mode is
411-
/// on the OS), but this should be extremely rare.
412-
static ref PERSISTENCE_LOCK: RwLock<()> = RwLock::new(());
413-
}
405+
/// Used to guard access to the persistence file(s) so that a single
406+
/// process will not step on its own toes.
407+
///
408+
/// We don't have much protecting us should two separate process try to
409+
/// write to the same file at once (depending on how atomic append mode is
410+
/// on the OS), but this should be extremely rare.
411+
static PERSISTENCE_LOCK: RwLock<()> = RwLock::new(());
414412

415413
#[cfg(test)]
416414
mod tests {
@@ -423,22 +421,20 @@ mod tests {
423421
misplaced_file: PathBuf,
424422
}
425423

426-
lazy_static! {
427-
static ref TEST_PATHS: TestPaths = {
428-
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
429-
let lib_root = crate_root.join("src");
430-
let src_subdir = lib_root.join("strategy");
431-
let src_file = lib_root.join("foo.rs");
432-
let subdir_file = src_subdir.join("foo.rs");
433-
let misplaced_file = crate_root.join("foo.rs");
434-
TestPaths {
435-
crate_root,
436-
src_file,
437-
subdir_file,
438-
misplaced_file,
439-
}
440-
};
441-
}
424+
static TEST_PATHS: std::sync::LazyLock<TestPaths> = std::sync::LazyLock::new(|| {
425+
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
426+
let lib_root = crate_root.join("src");
427+
let src_subdir = lib_root.join("strategy");
428+
let src_file = lib_root.join("foo.rs");
429+
let subdir_file = src_subdir.join("foo.rs");
430+
let misplaced_file = crate_root.join("foo.rs");
431+
TestPaths {
432+
crate_root,
433+
src_file,
434+
subdir_file,
435+
misplaced_file,
436+
}
437+
});
442438

443439
#[test]
444440
fn persistence_file_location_resolved_correctly() {
@@ -502,10 +498,7 @@ mod tests {
502498
#[test]
503499
fn relative_source_files_absolutified() {
504500
const TEST_RUNNER_PATH: &[&str] = &["src", "test_runner", "mod.rs"];
505-
lazy_static! {
506-
static ref TEST_RUNNER_RELATIVE: PathBuf =
507-
TEST_RUNNER_PATH.iter().collect();
508-
}
501+
static TEST_RUNNER_RELATIVE: std::sync::LazyLock<PathBuf> = std::sync::LazyLock::new(|| TEST_RUNNER_PATH.iter().collect());
509502
const CARGO_DIR: &str = env!("CARGO_MANIFEST_DIR");
510503

511504
let expected = ::std::iter::once(CARGO_DIR)
@@ -517,7 +510,7 @@ mod tests {
517510
&*expected,
518511
absolutize_source_file_with_cwd(
519512
|| Ok(Path::new(CARGO_DIR).to_owned()),
520-
&TEST_RUNNER_RELATIVE
513+
&*TEST_RUNNER_RELATIVE
521514
)
522515
.unwrap()
523516
);
@@ -527,7 +520,7 @@ mod tests {
527520
&*expected,
528521
absolutize_source_file_with_cwd(
529522
|| Ok(Path::new(CARGO_DIR).join("target")),
530-
&TEST_RUNNER_RELATIVE
523+
&*TEST_RUNNER_RELATIVE
531524
)
532525
.unwrap()
533526
);

0 commit comments

Comments
 (0)