From 4e34269d30e2f45479f28ac6734c1ac8661bd45d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 16 Sep 2024 12:28:59 +0200 Subject: [PATCH] Fix warnings about taking the address of a static ``` warning: creating a mutable reference to mutable static is discouraged --> src/main.rs:40:29 | 40 | unsafe { ALLOCATOR.init(&mut HEAP as *const u8 as usize, core::mem::size_of_val(&HEAP)) }; | ^^^^^^^^^ mutable reference to mutable static | = note: for more information, see issue #114447 = note: this will be a hard error in the 2024 edition = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior = note: `#[warn(static_mut_refs)]` on by default help: use `addr_of_mut!` instead to create a raw pointer | 40 | unsafe { ALLOCATOR.init(addr_of_mut!(HEAP) as *const u8 as usize, core::mem::size_of_val(&HEAP)) }; | ~~~~~~~~~~~~~ + ``` --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6be02e6..ac9d847 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ fn main() -> ! { static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE]; #[global_allocator] static ALLOCATOR: embedded_alloc::Heap = embedded_alloc::Heap::empty(); - unsafe { ALLOCATOR.init(&mut HEAP as *const u8 as usize, core::mem::size_of_val(&HEAP)) }; + unsafe { ALLOCATOR.init(core::ptr::addr_of_mut!(HEAP) as usize, HEAP_SIZE) } // -------- Setup peripherials -------- let mut pac = pac::Peripherals::take().unwrap();