Skip to content

Commit d9969a9

Browse files
authored
lazy_static → once_cell → stabilized versions (#3447)
* Anki: Replace lazy_static with once_cell Unify to once_cell, lazy_static's replacement. The latter in unmaintained. * Anki: Replace once_cell with stabilized LazyCell / LazyLock as far as possible Since 1.80: rust-lang/rust#109736 and rust-lang/rust#98165 Non-Thread-Safe Lazy → std::cell::LazyCell https://doc.rust-lang.org/nightly/std/cell/struct.LazyCell.html Thread-safe SyncLazy → std::sync::LazyLock https://doc.rust-lang.org/nightly/std/sync/struct.LazyLock.html The compiler accepted LazyCell only in minilints. The final use in rslib/src/log.rs couldn't be replaced since get_or_try_init has not yet been standardized: rust-lang/rust#109737 * Declare correct MSRV (dae) Some of our deps require newer Rust versions, so this was misleading. Updating the MSRV also allows us to use .inspect() on Option now
1 parent e2124cd commit d9969a9

File tree

39 files changed

+202
-222
lines changed

39 files changed

+202
-222
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version = "0.0.0"
33
authors = ["Ankitects Pty Ltd and contributors <https://help.ankiweb.net>"]
44
edition = "2021"
55
license = "AGPL-3.0-or-later"
6-
rust-version = "1.65"
6+
rust-version = "1.80"
77

88
[workspace]
99
members = [

build/ninja_gen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ camino.workspace = true
1414
dunce.workspace = true
1515
globset.workspace = true
1616
itertools.workspace = true
17-
lazy_static.workspace = true
1817
maplit.workspace = true
1918
num_cpus.workspace = true
2019
walkdir.workspace = true

build/ninja_gen/src/input.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::collections::HashMap;
55
use std::fmt::Display;
6+
use std::sync::LazyLock;
67

78
use camino::Utf8PathBuf;
89

@@ -118,9 +119,7 @@ pub struct Glob {
118119
pub exclude: Option<String>,
119120
}
120121

121-
lazy_static::lazy_static! {
122-
static ref CACHED_FILES: Vec<Utf8PathBuf> = cache_files();
123-
}
122+
static CACHED_FILES: LazyLock<Vec<Utf8PathBuf>> = LazyLock::new(cache_files);
124123

125124
/// Walking the source tree once instead of for each glob yields ~4x speed
126125
/// improvements.

ftl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ camino.workspace = true
1616
clap.workspace = true
1717
fluent-syntax.workspace = true
1818
itertools.workspace = true
19-
lazy_static.workspace = true
2019
regex.workspace = true
2120
serde_json.workspace = true
2221
snafu.workspace = true

ftl/src/garbage_collection.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fs;
66
use std::io::BufReader;
77
use std::iter::FromIterator;
88
use std::path::PathBuf;
9+
use std::sync::LazyLock;
910

1011
use anki_io::create_file;
1112
use anyhow::Context;
@@ -14,7 +15,6 @@ use clap::Args;
1415
use fluent_syntax::ast;
1516
use fluent_syntax::ast::Resource;
1617
use fluent_syntax::parser;
17-
use lazy_static::lazy_static;
1818
use regex::Regex;
1919
use walkdir::DirEntry;
2020
use walkdir::WalkDir;
@@ -144,9 +144,8 @@ fn extract_nested_messages_and_terms(
144144
ftl_roots: &[impl AsRef<str>],
145145
used_ftls: &mut HashSet<String>,
146146
) {
147-
lazy_static! {
148-
static ref REFERENCE: Regex = Regex::new(r"\{\s*-?([-0-9a-z]+)\s*\}").unwrap();
149-
}
147+
static REFERENCE: LazyLock<Regex> =
148+
LazyLock::new(|| Regex::new(r"\{\s*-?([-0-9a-z]+)\s*\}").unwrap());
150149
for_files_with_ending(ftl_roots, ".ftl", |entry| {
151150
let source = fs::read_to_string(entry.path()).expect("file not readable");
152151
for caps in REFERENCE.captures_iter(&source) {
@@ -198,11 +197,12 @@ fn entry_use_check(used_ftls: &HashSet<String>) -> impl Fn(&ast::Entry<&str>) ->
198197
}
199198

200199
fn extract_references_from_file(refs: &mut HashSet<String>, entry: &DirEntry) {
201-
lazy_static! {
202-
static ref SNAKECASE_TR: Regex = Regex::new(r"\Wtr\s*\.([0-9a-z_]+)\W").unwrap();
203-
static ref CAMELCASE_TR: Regex = Regex::new(r"\Wtr2?\.([0-9A-Za-z_]+)\W").unwrap();
204-
static ref DESIGNER_STYLE_TR: Regex = Regex::new(r"<string>([0-9a-z_]+)</string>").unwrap();
205-
}
200+
static SNAKECASE_TR: LazyLock<Regex> =
201+
LazyLock::new(|| Regex::new(r"\Wtr\s*\.([0-9a-z_]+)\W").unwrap());
202+
static CAMELCASE_TR: LazyLock<Regex> =
203+
LazyLock::new(|| Regex::new(r"\Wtr2?\.([0-9A-Za-z_]+)\W").unwrap());
204+
static DESIGNER_STYLE_TR: LazyLock<Regex> =
205+
LazyLock::new(|| Regex::new(r"<string>([0-9a-z_]+)</string>").unwrap());
206206

207207
let file_name = entry.file_name().to_str().expect("non-unicode filename");
208208

rslib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ htmlescape.workspace = true
6969
hyper.workspace = true
7070
id_tree.workspace = true
7171
itertools.workspace = true
72-
lazy_static.workspace = true
7372
nom.workspace = true
7473
num_cpus.workspace = true
7574
num_enum.workspace = true

rslib/linkchecker/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ rust-version.workspace = true
1111
anki.workspace = true
1212
futures.workspace = true
1313
itertools.workspace = true
14-
lazy_static.workspace = true
1514
linkcheck.workspace = true
1615
regex.workspace = true
1716
reqwest.workspace = true

rslib/linkchecker/tests/links.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use std::borrow::Cow;
77
use std::env;
88
use std::iter;
9+
use std::sync::LazyLock;
910
use std::time::Duration;
1011

1112
use anki::links::help_page_link_suffix;
1213
use anki::links::help_page_to_link;
1314
use anki::links::HelpPage;
1415
use futures::StreamExt;
1516
use itertools::Itertools;
16-
use lazy_static::lazy_static;
1717
use linkcheck::validation::check_web;
1818
use linkcheck::validation::Context;
1919
use linkcheck::validation::Reason;
@@ -70,9 +70,8 @@ impl From<&'static str> for CheckableUrl {
7070
}
7171

7272
fn ts_help_pages() -> impl Iterator<Item = &'static str> {
73-
lazy_static! {
74-
static ref QUOTED_URL: Regex = Regex::new("\"(http.+)\"").unwrap();
75-
}
73+
static QUOTED_URL: LazyLock<Regex> = LazyLock::new(|| Regex::new("\"(http.+)\"").unwrap());
74+
7675
QUOTED_URL
7776
.captures_iter(include_str!("../../../ts/lib/tslib/help-page.ts"))
7877
.map(|caps| caps.get(1).unwrap().as_str())

rslib/proto_gen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ anyhow.workspace = true
1515
camino.workspace = true
1616
inflections.workspace = true
1717
itertools.workspace = true
18-
once_cell.workspace = true
1918
prost-reflect.workspace = true
2019
prost-types.workspace = true
2120
regex.workspace = true

0 commit comments

Comments
 (0)