View all comments
Apparently it's undefined behaviour to use:
const gpio: &RegisterBlock = unsafe { (& (*lpc176x5x::GPIO::ptr())) };
but not undefined to use:
fn x() {
let gpio: &RegisterBlock = unsafe { (& (*lpc176x5x::GPIO::ptr())) };
(...)
}
with:
pub const fn ptr() -> *const gpio::RegisterBlock {
0x2009_c000 as *const _
}
Error message is:
error[E0080]: it is undefined behavior to use this value
--> src/rtos.rs:27:1
|
27 | const gpio: &RegisterBlock = unsafe { (& (*lpc176x5x::GPIO::ptr())) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (created from integer)
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
This is happening on in an embedded envrionment, where there is no MMU, and access to that address is correct.
I'm not sure why it would be undefined to use it as a const, but not undefined to use it as a variable value?
Perpahs it has something to do with the borrow checker not being able to track mutable and unmutable references to that value, but this is an immutable access, so it should be fine?
View all comments
Apparently it's undefined behaviour to use:
but not undefined to use:
with:
Error message is:
This is happening on in an embedded envrionment, where there is no MMU, and access to that address is correct.
I'm not sure why it would be undefined to use it as a const, but not undefined to use it as a variable value?
Perpahs it has something to do with the borrow checker not being able to track mutable and unmutable references to that value, but this is an immutable access, so it should be fine?