Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend std::sync::LazyLock over other lazy static options #12895

Open
pitaj opened this issue Jun 6, 2024 · 1 comment · May be fixed by #13770
Open

Recommend std::sync::LazyLock over other lazy static options #12895

pitaj opened this issue Jun 6, 2024 · 1 comment · May be fixed by #13770
Assignees
Labels
A-lint Area: New lints

Comments

@pitaj
Copy link
Contributor

pitaj commented Jun 6, 2024

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 or once_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());
@J-ZhengLi J-ZhengLi added the A-lint Area: New lints label Jun 7, 2024
@J-ZhengLi
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
2 participants