From 56789a6cab16a67d1e0028e5b235f62159f264ef Mon Sep 17 00:00:00 2001 From: Erwin van Eijk <235739+erwinvaneijk@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:42:36 +0200 Subject: [PATCH 1/3] feat(once_cell): remove dependency on once_cell Rust 1.80 has a proper implementation of LazyLock, which, when used, removes the dependency on once_cell. - update toolchain to 1.80.0 from 1.70.0 - remove once_cell from dependencies Fixes: #1169 --- Cargo.lock | 1 - Cargo.toml | 1 - rust-toolchain.toml | 2 +- src/fs/file.rs | 7 +++---- src/output/table.rs | 4 ++-- src/output/time.rs | 10 +++++----- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d8ac00c8..84267e833 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -453,7 +453,6 @@ dependencies = [ "natord", "nu-ansi-term", "number_prefix", - "once_cell", "palette", "path-clean", "percent-encoding", diff --git a/Cargo.toml b/Cargo.toml index b92e8418d..e8e82f37c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,6 @@ natord = "1.0" path-clean = "1.0.1" number_prefix = "0.4" palette = { version = "0.7.6", default-features = false, features = ["std"] } -once_cell = "1.20.1" percent-encoding = "2.3.1" phf = { version = "0.11.2", features = ["macros"] } plist = { version = "1.7.0", default-features = false } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f8b0aec75..3a3d2f50f 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2024 Christina Sørensen # SPDX-License-Identifier: EUPL-1.2 [toolchain] -channel = "1.70" +channel = "1.80" components = [ "rustfmt", "rustc", diff --git a/src/fs/file.rs b/src/fs/file.rs index 58e3bba09..e54d98d8c 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -25,7 +25,7 @@ use chrono::prelude::*; use log::*; #[cfg(unix)] -use once_cell::sync::Lazy; +use std::sync::LazyLock; use crate::fs::dir::Dir; use crate::fs::feature::xattr; @@ -40,11 +40,10 @@ use super::mounts::MountedFs; // Maps (device_id, inode) => (size_in_bytes, size_in_blocks) // Mutex::new is const but HashMap::new is not const requiring us to use lazy // initialization. -// TODO: Replace with std::sync::LazyLock when it is stable. #[allow(clippy::type_complexity)] #[cfg(unix)] -static DIRECTORY_SIZE_CACHE: Lazy>> = - Lazy::new(|| Mutex::new(HashMap::new())); +static DIRECTORY_SIZE_CACHE: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::new())); /// A **File** is a wrapper around one of Rust’s `PathBuf` values, along with /// associated data about the file. diff --git a/src/output/table.rs b/src/output/table.rs index 923039241..72d65585e 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -12,7 +12,7 @@ use std::sync::{Mutex, MutexGuard}; use chrono::prelude::*; use log::*; -use once_cell::sync::Lazy; +use std::sync::LazyLock; #[cfg(unix)] use uzers::UsersCache; @@ -398,7 +398,7 @@ impl Environment { } } -static ENVIRONMENT: Lazy = Lazy::new(Environment::load_all); +static ENVIRONMENT: LazyLock = LazyLock::new(Environment::load_all); pub struct Table<'a> { columns: Vec, diff --git a/src/output/time.rs b/src/output/time.rs index d1bc6ea5f..8935a574b 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -8,7 +8,7 @@ use chrono::prelude::*; use core::cmp::max; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::time::Duration; use unicode_width::UnicodeWidthStr; @@ -140,12 +140,12 @@ fn custom(time: &DateTime, non_recent_fmt: &str, recent_fmt: Option } } -static CURRENT_YEAR: Lazy = Lazy::new(|| Local::now().year()); +static CURRENT_YEAR: LazyLock = LazyLock::new(|| Local::now().year()); -static LOCALE: Lazy = - Lazy::new(|| locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english())); +static LOCALE: LazyLock = + LazyLock::new(|| locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english())); -static MAX_MONTH_WIDTH: Lazy = Lazy::new(|| { +static MAX_MONTH_WIDTH: LazyLock = LazyLock::new(|| { // Some locales use a three-character wide month name (Jan to Dec); // others vary between three to four (1月 to 12月, juil.). We check each month width // to detect the longest and set the output format accordingly. From dc6dd30cbe7a27aa787704fc215f9920d1c513a2 Mon Sep 17 00:00:00 2001 From: Erwin van Eijk <235739+erwinvaneijk@users.noreply.github.com> Date: Sun, 6 Oct 2024 19:09:42 +0200 Subject: [PATCH 2/3] feat: bump standard supported rust version --- .github/workflows/unit-tests.yml | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2894d1ac0..55b1a1132 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -33,7 +33,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - rust: [1.70.0, stable, beta, nightly] + rust: [1.80.0, stable, beta, nightly] steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index e8e82f37c..7e3ca7590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ description = "A modern replacement for ls" authors = ["Christina Sørensen "] categories = ["command-line-utilities"] edition = "2021" -rust-version = "1.70.0" +rust-version = "1.80.0" exclude = [ "/devtools/*", "/Justfile", From dd707090015c54e4ccb71092752842db5abe45ff Mon Sep 17 00:00:00 2001 From: Erwin van Eijk <235739+erwinvaneijk@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:38:18 +0200 Subject: [PATCH 3/3] fix: broken tests that rely on panic format - these tests rely on the way a panic is formatted, which changed from rustc 1.70 to 1.80 --- tests/gen/long_time_style_custom_non_recent_empty_nix.stderr | 3 ++- tests/gen/long_time_style_custom_non_recent_none_nix.stderr | 3 ++- tests/gen/long_time_style_custom_recent_empty_nix.stderr | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/gen/long_time_style_custom_non_recent_empty_nix.stderr b/tests/gen/long_time_style_custom_non_recent_empty_nix.stderr index 3ada3283f..295e1b87c 100644 --- a/tests/gen/long_time_style_custom_non_recent_empty_nix.stderr +++ b/tests/gen/long_time_style_custom_non_recent_empty_nix.stderr @@ -1,2 +1,3 @@ -thread 'main' panicked at 'Custom timestamp format is empty, please supply a chrono format string after the plus sign.', src/options/view.rs:357:21 +thread 'main' panicked at src/options/view.rs:357:21: +Custom timestamp format is empty, please supply a chrono format string after the plus sign. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/gen/long_time_style_custom_non_recent_none_nix.stderr b/tests/gen/long_time_style_custom_non_recent_none_nix.stderr index f03122381..bb38a7b17 100644 --- a/tests/gen/long_time_style_custom_non_recent_none_nix.stderr +++ b/tests/gen/long_time_style_custom_non_recent_none_nix.stderr @@ -1,2 +1,3 @@ -thread 'main' panicked at 'Custom timestamp format is empty, please supply a chrono format string after the plus sign.', src/options/view.rs:355:47 +thread 'main' panicked at src/options/view.rs:355:47: +Custom timestamp format is empty, please supply a chrono format string after the plus sign. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/gen/long_time_style_custom_recent_empty_nix.stderr b/tests/gen/long_time_style_custom_recent_empty_nix.stderr index 3c619484e..68b358378 100644 --- a/tests/gen/long_time_style_custom_recent_empty_nix.stderr +++ b/tests/gen/long_time_style_custom_recent_empty_nix.stderr @@ -1,2 +1,3 @@ -thread 'main' panicked at 'Custom timestamp format for recent files is empty, please supply a chrono format string at the second line.', src/options/view.rs:371:25 +thread 'main' panicked at src/options/view.rs:371:25: +Custom timestamp format for recent files is empty, please supply a chrono format string at the second line. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace