Fix warning: 'creating a shared reference to mutable static is discouraged' (#2230)

* Fix warning: 'creating a shared reference to mutable static is discouraged'

* Shorten lifetime of Clocks reference
This commit is contained in:
Dániel Buga 2024-09-25 17:31:24 +02:00 committed by GitHub
parent 3bb49b049a
commit feaf66847c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -319,15 +319,16 @@ impl Clocks {
})
}
fn try_get() -> Option<&'static Clocks> {
fn try_get<'a>() -> Option<&'a Clocks> {
unsafe {
// Safety: ACTIVE_CLOCKS is only set in `init` and never modified after that.
ACTIVE_CLOCKS.as_ref()
let clocks = &*core::ptr::addr_of!(ACTIVE_CLOCKS);
clocks.as_ref()
}
}
/// Get the active clock configuration.
pub fn get() -> &'static Clocks {
pub fn get<'a>() -> &'a Clocks {
unwrap!(Self::try_get())
}