From feaf66847cf6b8c9a8d43a10bbbf563853c2e39b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 25 Sep 2024 17:31:24 +0200 Subject: [PATCH] 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 --- esp-hal/src/clock/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esp-hal/src/clock/mod.rs b/esp-hal/src/clock/mod.rs index 1ad30294322..414cefa78a7 100644 --- a/esp-hal/src/clock/mod.rs +++ b/esp-hal/src/clock/mod.rs @@ -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()) }