Closed
Description
What it does
Warn on usage of the lazy_static!
macro or the Lazy
type from once_cell
in declarations of static
variables. Crates with an older MSRB or no_std
creates would be excluded.
These solutions have been superceded by the nearly stabilized std::sync::LazyLock
type (on track for 1.80.0).
Advantage
- Remove dependency on the
lazy_static
oronce_cell
crate - Enforce convention
Drawbacks
Churn
Example
lazy_static! {
static ref FOO: String = "foo".to_uppercase();
}
static BAR: Lazy<String> = Lazy::new(|| "BAR".to_lowercase());
Could be written as:
static FOO: LazyLock<String> = LazyLock::new(|| "foo".to_uppercase());
static BAR: LazyLock<String> = LazyLock::new(|| "BAR".to_lowercase());