From 9728ac5305cfe259115858f0bc49985a0ad7cec4 Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Sat, 14 Jun 2025 10:16:12 -0400 Subject: Adopt Rust 2024 edition I'm considering this a breaking change. I'll try to introduce new sections that rely on the user's `unsafe` keyword for linker placement. Rust 2024 has different opinions on format, and clippy has new thoughts. Let's adopt them. --- Cargo.toml | 4 ++-- board/Cargo.toml | 2 +- board/src/shared/imxrt10xx.rs | 2 +- board/src/shared/imxrt11xx.rs | 2 +- board/src/teensy4.rs | 8 ++++---- src/host.rs | 26 +++++++++++++------------- src/target.rs | 10 ++-------- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e532016..bb93245 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "imxrt-rt" -version = "0.1.7" -edition = "2021" +version = "0.2.0" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/imxrt-rs/imxrt-rt" description = "Startup and runtime support for i.MX RT processors." diff --git a/board/Cargo.toml b/board/Cargo.toml index 9afdfb0..836230c 100644 --- a/board/Cargo.toml +++ b/board/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "board" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies.cfg-if] diff --git a/board/src/shared/imxrt10xx.rs b/board/src/shared/imxrt10xx.rs index 5ba44eb..71a9065 100644 --- a/board/src/shared/imxrt10xx.rs +++ b/board/src/shared/imxrt10xx.rs @@ -4,7 +4,7 @@ use crate::ral; pub(crate) fn prepare_pit(timer_delay_microseconds: u32) -> Option { #[cfg(feature = "rtic")] { - extern "C" { + unsafe extern "C" { // Not actually mut in cortex-m. But, no one is reading it... static __INTERRUPTS: [core::cell::UnsafeCell; 240]; fn PIT(); diff --git a/board/src/shared/imxrt11xx.rs b/board/src/shared/imxrt11xx.rs index e0d1074..2620157 100644 --- a/board/src/shared/imxrt11xx.rs +++ b/board/src/shared/imxrt11xx.rs @@ -5,7 +5,7 @@ use crate::ral; pub(crate) fn prepare_pit(timer_delay_microseconds: u32) -> Option { #[cfg(feature = "rtic")] { - extern "C" { + unsafe extern "C" { // Not actually mut in cortex-m. But, no one is reading it... static __INTERRUPTS: [core::cell::UnsafeCell; 240]; fn PIT(); diff --git a/board/src/teensy4.rs b/board/src/teensy4.rs index 2aaee82..cf1f734 100644 --- a/board/src/teensy4.rs +++ b/board/src/teensy4.rs @@ -38,15 +38,15 @@ pub fn prepare(timer_delay_microseconds: u32) -> Option { /// Dummy DCD section containing a single NOP command (for testing linker scripts). #[cfg(feature = "__dcd")] -#[link_section = ".dcd"] -#[no_mangle] +#[unsafe(link_section = ".dcd")] +#[unsafe(no_mangle)] #[used] pub static DEVICE_CONFIGURATION_DATA: [u8; 8] = [0xD2, 0x00, 0x08, 0x41, 0xC0, 0x00, 0x04, 0x00]; /// Ditto but incorrect size (not a multiple of 4 bytes). The linker script should catch this error /// and fail the build. #[cfg(feature = "__dcd_missize")] -#[link_section = ".dcd"] -#[no_mangle] +#[unsafe(link_section = ".dcd")] +#[unsafe(no_mangle)] #[used] pub static DEVICE_CONFIGURATION_DATA: [u8; 7] = [0xD2, 0x00, 0x08, 0x41, 0xC0, 0x00, 0x04]; diff --git a/src/host.rs b/src/host.rs index ba299dd..2598d50 100644 --- a/src/host.rs +++ b/src/host.rs @@ -639,12 +639,12 @@ impl RuntimeBuilder { fn check_configurations(&self) -> Result<(), String> { if self.family.flexram_bank_count() < self.flexram_banks.bank_count() { return Err(format!( - "Chip {:?} only has {} total FlexRAM banks. Cannot allocate {:?}, a total of {} banks", - self.family, - self.family.flexram_bank_count(), - self.flexram_banks, - self.flexram_banks.bank_count() - )); + "Chip {:?} only has {} total FlexRAM banks. Cannot allocate {:?}, a total of {} banks", + self.family, + self.family.flexram_bank_count(), + self.flexram_banks, + self.flexram_banks.bank_count() + )); } if self.flexram_banks.ocram < self.family.bootrom_ocram_banks() { return Err(format!( @@ -653,13 +653,13 @@ impl RuntimeBuilder { self.family.bootrom_ocram_banks() )); } - if let Some(flash_opts) = &self.flash_opts { - if !flash_opts.flexspi.supported_for_family(self.family) { - return Err(format!( - "Chip {:?} does not support {:?}", - self.family, flash_opts.flexspi - )); - } + if let Some(flash_opts) = &self.flash_opts + && !flash_opts.flexspi.supported_for_family(self.family) + { + return Err(format!( + "Chip {:?} does not support {:?}", + self.family, flash_opts.flexspi + )); } fn prevent_flash(name: &str, memory: Memory) -> Result<(), String> { diff --git a/src/target.rs b/src/target.rs index 98072e0..d0e2223 100644 --- a/src/target.rs +++ b/src/target.rs @@ -135,14 +135,8 @@ __pre_init: /// The returned pointer is guaranteed to be 4-byte aligned. #[inline] pub fn heap_end() -> *mut u32 { - extern "C" { + unsafe extern "C" { static mut __eheap: c_void; } - - // It used to be unsafe. Keeping it unsafe is backwards - // compatible. - #[allow(unused_unsafe)] - unsafe { - core::ptr::addr_of_mut!(__eheap) as _ - } + &raw mut __eheap as _ } -- cgit v1.2.3