Skip to content

Commit acd33f4

Browse files
authored
Drop once_cell::sync::Lazy in favor of std::sync::LazyLock
This almost completely drops the `once_cell` crate, but `OnceCell` is still in use. While the `OnceCell` type is available in the standard library, the `get_or_try_init` method is not yet stabilized. This bumps the MSRV up to 1.80, which is the first version to stabilize `std::sync::LazyLock`.
1 parent 7c00d13 commit acd33f4

File tree

31 files changed

+63
-81
lines changed

31 files changed

+63
-81
lines changed

.github/workflows/msrv.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
env:
2626
# dictated by `firefox` to support the `helix` editor, but now probably effectively be controlled by `jiff`, which also aligns with `regex`.
2727
# IMPORTANT: adjust etc/msrv-badge.svg as well
28-
rust_version: 1.74.0
28+
rust_version: 1.80.0
2929
steps:
3030
- uses: actions/checkout@v4
3131
- uses: extractions/setup-just@v2

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ terminal_size = "0.3.0"
190190
# Avoid pre-compiled binaries, see https://github.com/serde-rs/serde/issues/2538 and https://github.com/serde-rs/serde/pull/2590
191191
serde_derive = ">=1.0.185"
192192

193-
once_cell = "1.18.0"
194193
document-features = { version = "0.2.0", optional = true }
195194

196195
[profile.dev.package]

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.74.0"
1+
msrv = "1.80.0"

etc/msrv-badge.svg

Lines changed: 3 additions & 3 deletions
Loading

gix-config/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
keywords = ["git-config", "git", "config", "gitoxide"]
1010
categories = ["config", "parser-implementations"]
1111
include = ["src/**/*", "LICENSE-*", "README.md"]
12-
rust-version = "1.65"
12+
rust-version = "1.80"
1313
autotests = false
1414

1515
[features]
@@ -31,7 +31,6 @@ unicode-bom.workspace = true
3131
bstr = { version = "1.3.0", default-features = false, features = ["std"] }
3232
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
3333
smallvec = "1.9.0"
34-
once_cell = "1.14.0"
3534

3635
document-features = { version = "0.2.0", optional = true }
3736

gix-credentials/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ document-features = { version = "0.2.1", optional = true }
3636
[dev-dependencies]
3737
gix-testtools = { path = "../tests/tools" }
3838
gix-sec = { path = "../gix-sec" }
39-
once_cell = "1.19.0"
4039

4140
[package.metadata.docs.rs]
4241
all-features = true

gix-credentials/tests/program/from_custom_definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use gix_credentials::{helper, program::Kind, Program};
22

3-
static GIT: once_cell::sync::Lazy<&'static str> =
4-
once_cell::sync::Lazy::new(|| gix_path::env::exe_invocation().to_str().expect("not illformed"));
3+
static GIT: std::sync::LazyLock<&'static str> =
4+
std::sync::LazyLock::new(|| gix_path::env::exe_invocation().to_str().expect("not illformed"));
55

66
#[cfg(windows)]
77
const SH: &str = "sh";

gix-date/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ document-features = { version = "0.2.0", optional = true }
2727

2828
[dev-dependencies]
2929
gix-testtools = { path = "../tests/tools" }
30-
once_cell = "1.12.0"
3130
gix-hash = { path = "../gix-hash" }
3231

3332
[package.metadata.docs.rs]

gix-date/tests/time/baseline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use gix_date::{
55
SecondsSinceUnixEpoch,
66
};
77
use gix_testtools::Result;
8-
use once_cell::sync::Lazy;
8+
use std::sync::LazyLock;
99

1010
struct Sample {
1111
format_name: Option<String>,
1212
exit_code: usize,
1313
seconds: SecondsSinceUnixEpoch,
1414
}
1515

16-
static BASELINE: Lazy<HashMap<String, Sample>> = Lazy::new(|| {
16+
static BASELINE: LazyLock<HashMap<String, Sample>> = LazyLock::new(|| {
1717
(|| -> Result<_> {
1818
let base = gix_testtools::scripted_fixture_read_only("generate_git_date_baseline.sh")?;
1919
let mut map = HashMap::new();

gix-fsck/tests/connectivity/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gix_fsck::Connectivity;
22
use gix_hash::ObjectId;
33
use gix_hashtable::HashMap;
44
use gix_object::Kind;
5-
use gix_testtools::once_cell::sync::Lazy;
5+
use std::sync::LazyLock;
66

77
use crate::hex_to_id;
88

@@ -40,7 +40,7 @@ fn hex_to_objects<'a>(hex_ids: impl IntoIterator<Item = &'a str>, kind: Kind) ->
4040

4141
// Get a `&Vec<ObjectID` for each commit in the test fixture repository
4242
fn all_commits() -> &'static [ObjectId] {
43-
static ALL_COMMITS: Lazy<Vec<ObjectId>> = Lazy::new(|| {
43+
static ALL_COMMITS: LazyLock<Vec<ObjectId>> = LazyLock::new(|| {
4444
hex_to_ids([
4545
"ebed23648b19484cb1f340c4ee04dda08479188a",
4646
"8ff6d0f8891c3cb22827be142cc64606121d47b3",

gix-path/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "A crate of the gitoxide project dealing paths and their conversio
77
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
88
edition = "2021"
99
include = ["src/**/*", "LICENSE-*"]
10-
rust-version = "1.65"
10+
rust-version = "1.80"
1111

1212
[lib]
1313
doctest = false
@@ -16,7 +16,6 @@ doctest = false
1616
gix-trace = { version = "^0.1.8", path = "../gix-trace" }
1717
bstr = { version = "1.3.0", default-features = false, features = ["std"] }
1818
thiserror = "1.0.26"
19-
once_cell = "1.17.1"
2019

2120
[target.'cfg(not(target_family = "wasm"))'.dependencies]
2221
home = "0.5.5"

gix-path/src/env/git/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::path::{Path, PathBuf};
22
use std::process::{Command, Stdio};
33

44
use bstr::{BStr, BString, ByteSlice};
5-
use once_cell::sync::Lazy;
5+
use std::sync::LazyLock;
66

77
/// Other places to find Git in.
88
#[cfg(windows)]
9-
pub(super) static ALTERNATIVE_LOCATIONS: Lazy<Vec<PathBuf>> =
10-
Lazy::new(|| locations_under_program_files(|key| std::env::var_os(key)));
9+
pub(super) static ALTERNATIVE_LOCATIONS: LazyLock<Vec<PathBuf>> =
10+
LazyLock::new(|| locations_under_program_files(|key| std::env::var_os(key)));
1111
#[cfg(not(windows))]
12-
pub(super) static ALTERNATIVE_LOCATIONS: Lazy<Vec<PathBuf>> = Lazy::new(Vec::new);
12+
pub(super) static ALTERNATIVE_LOCATIONS: LazyLock<Vec<PathBuf>> = LazyLock::new(Vec::new);
1313

1414
#[cfg(windows)]
1515
fn locations_under_program_files<F>(var_os_func: F) -> Vec<PathBuf>
@@ -79,7 +79,7 @@ pub(super) static EXE_NAME: &str = "git";
7979
/// Invoke the git executable to obtain the origin configuration, which is cached and returned.
8080
///
8181
/// The git executable is the one found in PATH or an alternative location.
82-
pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(|| {
82+
pub(super) static EXE_INFO: LazyLock<Option<BString>> = LazyLock::new(|| {
8383
let git_cmd = |executable: PathBuf| {
8484
let mut cmd = Command::new(executable);
8585
#[cfg(windows)]
@@ -119,7 +119,7 @@ pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(|| {
119119
/// errors during execution.
120120
pub(super) fn install_config_path() -> Option<&'static BStr> {
121121
let _span = gix_trace::detail!("gix_path::git::install_config_path()");
122-
static PATH: Lazy<Option<BString>> = Lazy::new(|| {
122+
static PATH: LazyLock<Option<BString>> = LazyLock::new(|| {
123123
// Shortcut: Specifically in Git for Windows 'Git Bash' shells, this variable is set. It
124124
// may let us deduce the installation directory, so we can save the `git` invocation.
125125
#[cfg(windows)]

gix-path/src/env/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ffi::OsString;
22
use std::path::{Path, PathBuf};
33

44
use bstr::{BString, ByteSlice};
5-
use once_cell::sync::Lazy;
5+
use std::sync::LazyLock;
66

77
use crate::env::git::EXE_NAME;
88

@@ -37,7 +37,7 @@ pub fn exe_invocation() -> &'static Path {
3737
if cfg!(windows) {
3838
/// The path to the Git executable as located in the `PATH` or in other locations that it's known to be installed to.
3939
/// It's `None` if environment variables couldn't be read or if no executable could be found.
40-
static EXECUTABLE_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
40+
static EXECUTABLE_PATH: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
4141
std::env::split_paths(&std::env::var_os("PATH")?)
4242
.chain(git::ALTERNATIVE_LOCATIONS.iter().map(Into::into))
4343
.find_map(|prefix| {
@@ -98,7 +98,7 @@ pub fn xdg_config(file: &str, env_var: &mut dyn FnMut(&str) -> Option<OsString>)
9898
/// wasn't built with a well-known directory structure or environment.
9999
pub fn system_prefix() -> Option<&'static Path> {
100100
if cfg!(windows) {
101-
static PREFIX: Lazy<Option<PathBuf>> = Lazy::new(|| {
101+
static PREFIX: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
102102
if let Some(root) = std::env::var_os("EXEPATH").map(PathBuf::from) {
103103
for candidate in ["mingw64", "mingw32"] {
104104
let candidate = root.join(candidate);

gix-pathspec/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ thiserror = "1.0.26"
2424

2525
[dev-dependencies]
2626
gix-testtools = { path = "../tests/tools" }
27-
once_cell = "1.12.0"
2827
serial_test = "3.1.1"

gix-pathspec/tests/parse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use bstr::{BStr, BString, ByteSlice};
44
use gix_attributes::State;
55
use gix_pathspec::{MagicSignature, Pattern, SearchMode};
6-
use once_cell::sync::Lazy;
6+
use std::sync::LazyLock;
77

88
#[test]
99
fn baseline() {
@@ -54,7 +54,7 @@ impl From<Pattern> for NormalizedPattern {
5454
}
5555
}
5656

57-
static BASELINE: Lazy<HashMap<BString, usize>> = Lazy::new(|| {
57+
static BASELINE: LazyLock<HashMap<BString, usize>> = LazyLock::new(|| {
5858
let base = gix_testtools::scripted_fixture_read_only("parse_baseline.sh").unwrap();
5959

6060
(|| -> crate::Result<_> {

gix-refspec/tests/matching/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use gix_testtools::once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

3-
static BASELINE: Lazy<baseline::Baseline> = Lazy::new(|| baseline::parse().unwrap());
3+
static BASELINE: LazyLock<baseline::Baseline> = LazyLock::new(|| baseline::parse().unwrap());
44

55
pub mod baseline {
66
use std::{borrow::Borrow, collections::HashMap};
@@ -12,7 +12,7 @@ pub mod baseline {
1212
parse::Operation,
1313
MatchGroup,
1414
};
15-
use gix_testtools::once_cell::sync::Lazy;
15+
use std::sync::LazyLock;
1616

1717
use crate::matching::BASELINE;
1818

@@ -34,7 +34,7 @@ pub mod baseline {
3434
}
3535
}
3636

37-
static INPUT: Lazy<Vec<Ref>> = Lazy::new(|| parse_input().unwrap());
37+
static INPUT: LazyLock<Vec<Ref>> = LazyLock::new(|| parse_input().unwrap());
3838

3939
pub type Baseline = HashMap<Vec<BString>, Result<Vec<Mapping>, BString>>;
4040

gix-tempfile/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "A tempfile implementation with a global registry to assure cleanu
77
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
88
edition = "2021"
99
include = ["src/**/*", "LICENSE-*", "README.md"]
10-
rust-version = "1.65"
10+
rust-version = "1.80"
1111

1212
[[example]]
1313
name = "delete-tempfiles-on-sigterm"
@@ -32,7 +32,6 @@ test = true
3232
gix-fs = { version = "^0.11.2", path = "../gix-fs" }
3333
parking_lot = "0.12.1"
3434
dashmap = { version = "6.0.1", optional = true }
35-
once_cell = { version = "1.8.0", default-features = false, features = ["race", "std"] }
3635
tempfile = "3.10.0"
3736

3837
signal-hook = { version = "0.3.9", default-features = false, optional = true }

gix-tempfile/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::{
4141
sync::atomic::AtomicUsize,
4242
};
4343

44-
use once_cell::sync::Lazy;
44+
use std::sync::LazyLock;
4545

4646
#[cfg(feature = "hp-hashmap")]
4747
type HashMap<K, V> = dashmap::DashMap<K, V>;
@@ -112,7 +112,7 @@ use crate::handle::{Closed, Writable};
112112
pub mod registry;
113113

114114
static NEXT_MAP_INDEX: AtomicUsize = AtomicUsize::new(0);
115-
static REGISTRY: Lazy<HashMap<usize, Option<ForksafeTempfile>>> = Lazy::new(|| {
115+
static REGISTRY: LazyLock<HashMap<usize, Option<ForksafeTempfile>>> = LazyLock::new(|| {
116116
#[cfg(feature = "signals")]
117117
if signal::handler::MODE.load(std::sync::atomic::Ordering::SeqCst) != signal::handler::Mode::None as usize {
118118
for sig in signal_hook::consts::TERM_SIGNALS {

gix-tempfile/src/signal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use crate::REGISTRY;
44

@@ -12,7 +12,7 @@ use crate::REGISTRY;
1212
/// from a signal handler under the application's control.
1313
pub fn setup(mode: handler::Mode) {
1414
handler::MODE.store(mode as usize, std::sync::atomic::Ordering::SeqCst);
15-
Lazy::force(&REGISTRY);
15+
LazyLock::force(&REGISTRY);
1616
}
1717

1818
///

0 commit comments

Comments
 (0)