Skip to content

Commit 0abebb2

Browse files
committed
*: migrate from once_cell to std::sync::LazyLock
This was only stabilised in Rust 1.80.0, so this might cause issues when building on older distributions (depending on when libpathrs starts getting packaged). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 5e31275 commit 0abebb2

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ bitflags = "^2"
5050
itertools = "^0.13"
5151
libc = "^0.2"
5252
memchr = "^2"
53-
# MSRV(1.80): Use LazyLock.
54-
once_cell = "^1"
5553
# MSRV(1.65): Update to >=0.4.1 which uses let_else. 0.4.0 was broken.
5654
open-enum = { version = "=0.3.0", optional = true }
5755
rand = { version = "^0.8", optional = true }

src/capi/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ use std::{
2727
error::Error as StdError,
2828
ffi::CString,
2929
ptr,
30-
sync::Mutex,
30+
sync::{LazyLock, Mutex},
3131
};
3232

3333
use libc::{c_char, c_int};
34-
use once_cell::sync::Lazy;
3534
use rand::{self, Rng};
3635

3736
// TODO: Switch this to using a slab or similar structure, possibly using a less heavy-weight lock?
38-
// MSRV(1.80): Use LazyLock.
39-
static ERROR_MAP: Lazy<Mutex<HashMap<CReturn, Error>>> = Lazy::new(|| Mutex::new(HashMap::new()));
37+
static ERROR_MAP: LazyLock<Mutex<HashMap<CReturn, Error>>> =
38+
LazyLock::new(|| Mutex::new(HashMap::new()));
4039

4140
pub(crate) fn store_error(err: Error) -> CReturn {
4241
let mut err_map = ERROR_MAP.lock().unwrap();

src/procfs.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ use std::{
3434
io::Error as IOError,
3535
os::unix::io::{AsFd, BorrowedFd, OwnedFd},
3636
path::{Path, PathBuf},
37+
sync::LazyLock,
3738
};
3839

39-
use once_cell::sync::Lazy;
4040
use rustix::fs::{self as rustix_fs, Access, AtFlags};
4141

4242
/// A `procfs` handle to which is used globally by libpathrs.
43-
// MSRV(1.80): Use LazyLock.
44-
pub(crate) static GLOBAL_PROCFS_HANDLE: Lazy<ProcfsHandle> =
45-
Lazy::new(|| ProcfsHandle::new().expect("should be able to get some /proc handle"));
43+
pub(crate) static GLOBAL_PROCFS_HANDLE: LazyLock<ProcfsHandle> =
44+
LazyLock::new(|| ProcfsHandle::new().expect("should be able to get some /proc handle"));
4645

4746
/// Indicate what base directory should be used when doing `/proc/...`
4847
/// operations with a [`ProcfsHandle`].

src/resolvers/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ use std::{
3131
os::unix::io::{AsFd, OwnedFd},
3232
path::{Path, PathBuf},
3333
rc::Rc,
34+
sync::LazyLock,
3435
};
3536

36-
use once_cell::sync::Lazy;
37-
3837
/// `O_PATH`-based userspace resolver.
3938
pub(crate) mod opath;
4039
/// `openat2(2)`-based in-kernel resolver.
@@ -65,8 +64,7 @@ pub(crate) enum ResolverBackend {
6564
// hyper-concerned users.
6665
}
6766

68-
// MSRV(1.80): Use LazyLock.
69-
static DEFAULT_RESOLVER_TYPE: Lazy<ResolverBackend> = Lazy::new(|| {
67+
static DEFAULT_RESOLVER_TYPE: LazyLock<ResolverBackend> = LazyLock::new(|| {
7068
if *syscalls::OPENAT2_IS_SUPPORTED {
7169
ResolverBackend::KernelOpenat2
7270
} else {

src/resolvers/opath/impl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ use std::{
5858
},
5959
path::{Path, PathBuf},
6060
rc::Rc,
61+
sync::LazyLock,
6162
};
6263

6364
use itertools::Itertools;
64-
use once_cell::sync::Lazy;
6565

6666
/// Ensure that the expected path within the root matches the current fd.
6767
fn check_current<RootFd: AsFd, Fd: AsFd, P: AsRef<Path>>(
@@ -135,8 +135,7 @@ fn check_current<RootFd: AsFd, Fd: AsFd, P: AsRef<Path>>(
135135
// TODO: In theory this value could change during the lifetime of the
136136
// program, but there's no nice way of detecting that, and the overhead of
137137
// checking this for every symlink lookup is more likely to be an issue.
138-
// MSRV(1.80): Use LazyLock.
139-
static PROTECTED_SYMLINKS_SYSCTL: Lazy<u32> = Lazy::new(|| {
138+
static PROTECTED_SYMLINKS_SYSCTL: LazyLock<u32> = LazyLock::new(|| {
140139
utils::sysctl_read_parse(&GLOBAL_PROCFS_HANDLE, "fs.protected_symlinks")
141140
.expect("should be able to parse fs.protected_symlinks")
142141
});

src/syscalls.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ use std::{
3535
},
3636
path::{Path, PathBuf},
3737
ptr,
38+
sync::LazyLock,
3839
};
3940

4041
use libc::{c_int, c_uint, dev_t, mode_t, stat, statfs};
41-
use once_cell::sync::Lazy;
4242

4343
// TODO: Figure out how we can put a backtrace here (it seems we can't use
4444
// thiserror's backtrace support without nightly Rust because thiserror
@@ -555,8 +555,7 @@ pub(crate) fn renameat<Fd1: AsFd, P1: AsRef<Path>, Fd2: AsFd, P2: AsRef<Path>>(
555555
}
556556
}
557557

558-
// MSRV(1.80): Use LazyLock.
559-
pub(crate) static RENAME_FLAGS_SUPPORTED: Lazy<bool> = Lazy::new(|| {
558+
pub(crate) static RENAME_FLAGS_SUPPORTED: LazyLock<bool> = LazyLock::new(|| {
560559
match renameat2(AT_FDCWD, ".", AT_FDCWD, ".", libc::RENAME_EXCHANGE) {
561560
Ok(_) => true,
562561
// We expect EBUSY, but just to be safe we only check for ENOSYS.
@@ -702,9 +701,8 @@ pub(crate) fn statx<Fd: AsFd, P: AsRef<Path>>(
702701
}
703702
}
704703

705-
// MSRV(1.80): Use LazyLock.
706-
pub(crate) static OPENAT2_IS_SUPPORTED: Lazy<bool> =
707-
Lazy::new(|| openat2(AT_FDCWD, ".", &Default::default()).is_ok());
704+
pub(crate) static OPENAT2_IS_SUPPORTED: LazyLock<bool> =
705+
LazyLock::new(|| openat2(AT_FDCWD, ".", &Default::default()).is_ok());
708706

709707
bitflags! {
710708
/// Wrapper for the underlying `libc`'s `RESOLVE_*` flags.

0 commit comments

Comments
 (0)