Skip to content

Commit

Permalink
Fix warning: 'creating a shared reference to mutable static is discou…
Browse files Browse the repository at this point in the history
…raged' (#2230)

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

* Shorten lifetime of Clocks reference
  • Loading branch information
bugadani authored Sep 25, 2024
1 parent 3bb49b0 commit feaf668
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions esp-hal/src/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down

0 comments on commit feaf668

Please sign in to comment.