Skip to content

Commit 034eb3d

Browse files
committed
context: whitelist new compiler warning
The compiler doesn't like shared references to static mut variables, because it is worried that we'll share a reference while a mutation happens which is UB. We are only sharing references after using Once to do a one-time initialization, so this is fine, but in recent versions of the compiler there is an encapsulated form of this pattern called `OnceLock` and a variant called `LazyLock`. Neither of these are available on our MSRV so just whitelist the lint.
1 parent 65715a5 commit 034eb3d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub mod global {
4242
type Target = Secp256k1<All>;
4343

4444
#[allow(unused_mut)] // Unused when `rand` + `std` is not enabled.
45+
#[allow(static_mut_refs)] // The "proper" way to do this is with OnceLock (MSRV 1.70) or LazyLock (MSRV 1.80)
46+
// See https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html
4547
fn deref(&self) -> &Self::Target {
4648
static ONCE: Once = Once::new();
4749
static mut CONTEXT: Option<Secp256k1<All>> = None;

0 commit comments

Comments
 (0)