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

Replaces static mutable references in perf_libs #4417

Conversation

brooksprumo
Copy link

@brooksprumo brooksprumo commented Jan 12, 2025

Problem

New clippy lints when upgrading to rust 1.84.0.

Some are related to creating references to mutable statics. Here's the new lint for perf::perf_libs:

warning: creating a shared reference to mutable static is discouraged
   --> perf/src/perf_libs.rs:187:14
    |
187 |     unsafe { API.as_ref() }
    |              ^^^^^^^^^^^^ shared reference to mutable static
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
    = note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
    = note: `#[warn(static_mut_refs)]` on by default

Summary of Changes

Replace Once with OnceLock for the API, as it is the preferred way to do Once+data.

Partially fixes #4380

@brooksprumo brooksprumo self-assigned this Jan 12, 2025
@brooksprumo brooksprumo marked this pull request as ready for review January 13, 2025 01:32
Copy link

@alexpyattaev alexpyattaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@brooksprumo brooksprumo requested a review from sakridge January 13, 2025 14:54
@brooksprumo
Copy link
Author

@sakridge Can I get your review on this as well, please? I want to ensure there's not something I've overlooked here.

@brooksprumo brooksprumo merged commit e7301b2 into anza-xyz:master Jan 14, 2025
47 checks passed
@brooksprumo brooksprumo deleted the rust-1.84.0/clippy/static-mut-refs/perf_libs branch January 14, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New clippy lints in Rust 1.84.0
3 participants