Idea / Pre-RFC: Null-free pointer and Zeroable reference
Rust Internals [Unofficial]
March 11, 2026
Hello,
Just my 2 cents on this, I implemented the bootloader for the MCU with program RAM at address 0x0. I will probably update my implementation to use read_volatile now. might be that this did not work when I first wrote this or I simply missed the option. Both options used in this code snippet work just fine:
#[entry]
fn main() -> ! {
(...)
#[allow(clippy::zero_ptr)]
let first_four_bytes_volatile_read = unsafe { core::ptr::read_volatile(0x0000_0000 as *const u32) }.to_ne_bytes();
let mut buf: [u8; 4] = [0; 4];
read_four_bytes_at_addr_zero(&mut buf);
assert_eq!(first_four_bytes_volatile_read, buf);
}
fn read_four_bytes_at_addr_zero(buf: &mut [u8; 4]) {
#[allow(clippy::zero_ptr)]
unsafe {
core::arch::asm!(
"ldr r0, [{0}]", // Load 4 bytes from src into r0 register
"str r0, [{1}]", // Store r0 register into first_four_bytes
in(reg) 0x0 as *const u8, // Input: src pointer (0x0)
in(reg) buf as *mut [u8; 4], // Input: destination pointer
);
}
}
On the RFC: I am happy with the way this is now without requiring special language level support, especially now that I know I can use a volatile read for that special case in my bootloader (no assembly required). I have not read all the discussion, but the gist seems to be that this feature is not worth the drawbacks it would mean, especially because there are solutions for them.
Discussion in the ATmosphere