Skip to content

Commit 67ce796

Browse files
Replace lazy_static with once_cell
1 parent 37b754f commit 67ce796

9 files changed

Lines changed: 15 additions & 33 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ uudoc = [ "zip" ]
261261
[dependencies]
262262
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
263263
clap_complete = "3.1"
264+
once_cell = "1.13.0"
264265
phf = "0.10.1"
265-
lazy_static = { version="1.3" }
266+
selinux = { version="0.2", optional = true }
266267
textwrap = { version="0.15", features=["terminal_size"] }
267268
uucore = { version=">=0.0.11", package="uucore", path="src/uucore" }
268-
selinux = { version="0.2", optional = true }
269269
zip = { version = "0.6.0", optional=true, default_features=false, features=["deflate"] }
270270
# * uutils
271271
uu_test = { optional=true, version="0.0.14", package="uu_test", path="src/uu/test" }

src/uu/ls/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ once_cell = "1.13.0"
2828
atty = "0.2"
2929
selinux = { version="0.2", optional = true }
3030

31-
[target.'cfg(unix)'.dependencies]
32-
lazy_static = "1.4.0"
33-
3431
[[bin]]
3532
name = "ls"
3633
path = "src/main.rs"

src/uu/ls/src/ls.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
#[macro_use]
1111
extern crate uucore;
12-
#[cfg(unix)]
13-
#[macro_use]
14-
extern crate lazy_static;
1512

1613
use clap::{crate_version, Arg, Command};
1714
use glob::Pattern;
@@ -2251,16 +2248,16 @@ fn get_inode(metadata: &Metadata) -> String {
22512248
// Currently getpwuid is `linux` target only. If it's broken out into
22522249
// a posix-compliant attribute this can be updated...
22532250
#[cfg(unix)]
2251+
use once_cell::sync::Lazy;
2252+
#[cfg(unix)]
22542253
use std::sync::Mutex;
22552254
#[cfg(unix)]
22562255
use uucore::entries;
22572256
use uucore::quoting_style;
22582257

22592258
#[cfg(unix)]
22602259
fn cached_uid2usr(uid: u32) -> String {
2261-
lazy_static! {
2262-
static ref UID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
2263-
}
2260+
static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
22642261

22652262
let mut uid_cache = UID_CACHE.lock().unwrap();
22662263
uid_cache
@@ -2280,9 +2277,7 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
22802277

22812278
#[cfg(all(unix, not(target_os = "redox")))]
22822279
fn cached_gid2grp(gid: u32) -> String {
2283-
lazy_static! {
2284-
static ref GID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
2285-
}
2280+
static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
22862281

22872282
let mut gid_cache = GID_CACHE.lock().unwrap();
22882283
gid_cache

src/uucore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ nix = { version = "0.24.1", optional = true, default-features = false, features
4141

4242
[dev-dependencies]
4343
clap = "3.1"
44-
lazy_static = "1.3"
44+
once_cell = "1.13"
4545

4646
[target.'cfg(target_os = "windows")'.dependencies]
4747
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }

src/uucore/src/lib/mods/backup_control.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ mod tests {
447447
use std::env;
448448
// Required to instantiate mutex in shared context
449449
use clap::Command;
450-
use lazy_static::lazy_static;
450+
use once_cell::sync::Lazy;
451451
use std::sync::Mutex;
452452

453453
// The mutex is required here as by default all tests are run as separate
@@ -456,9 +456,7 @@ mod tests {
456456
// occur if no precautions are taken. Thus we have all tests that rely on
457457
// environment variables lock this empty mutex to ensure they don't access
458458
// it concurrently.
459-
lazy_static! {
460-
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
461-
}
459+
static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
462460

463461
// Environment variable for "VERSION_CONTROL"
464462
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

tests/by-util/test_chmod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::common::util::*;
22
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
33
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
44
use std::sync::Mutex;
5+
use once_cell::sync::Lazy;
56

67
extern crate libc;
78
use uucore::mode::strip_minus_from_mode;
@@ -11,9 +12,7 @@ use self::libc::umask;
1112
static TEST_FILE: &str = "file";
1213
static REFERENCE_FILE: &str = "reference";
1314
static REFERENCE_PERMS: u32 = 0o247;
14-
lazy_static! {
15-
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
16-
}
15+
static UMASK_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
1716

1817
struct TestCase {
1918
args: Vec<&'static str>,

tests/by-util/test_ls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use std::path::Path;
1919
#[cfg(not(windows))]
2020
use std::path::PathBuf;
2121
#[cfg(not(windows))]
22+
use once_cell::sync::Lazy;
23+
#[cfg(not(windows))]
2224
use std::sync::Mutex;
2325
use std::thread::sleep;
2426
use std::time::Duration;
2527

2628
#[cfg(not(windows))]
27-
lazy_static! {
28-
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
29-
}
29+
static UMASK_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
3030

3131
const LONG_ARGS: &[&str] = &[
3232
"-l",

tests/tests.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#[macro_use]
22
mod common;
33

4-
#[allow(unused_imports)]
5-
#[cfg(unix)]
6-
#[macro_use]
7-
extern crate lazy_static;
8-
94
#[cfg(unix)]
105
extern crate rust_users;
116

0 commit comments

Comments
 (0)