diff --git a/examples/bare4.rs b/examples/bare4.rs index 1a381a517b2ce92fcae68f32cb0fae1ccbd8f460..5186bc9b000e64b04000b4b25b57b9c644687ba8 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -36,8 +36,8 @@ use address::*; #[inline(always)] fn read_u32(addr: u32) -> u32 { - unsafe { core::ptr::read_volatile(addr as *const _) } - //core::ptr::read_volatile(addr as *const _) + // unsafe { core::ptr::read_volatile(addr as *const _) } + core::ptr::read_volatile(addr as *const _) } #[inline(always)] @@ -106,6 +106,17 @@ fn main() -> ! { // What was the error message and explain why. // // ** your answer here ** +// error[E0133]: call to unsafe function is unsafe and requires unsafe function or block +// --> examples/bare4.rs:40:5 +// | +// 40 | core::ptr::read_volatile(addr as *const _) +// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function +// | +// = note: consult the function's documentation for information on how to avoid undefined behavior +// +// error: aborting due to previous error +// +// Reading adresses is not safe so it panics // // Digging a bit deeper, why do you think `read_volatile` is declared `unsafe`. // (https://doc.rust-lang.org/core/ptr/fn.read_volatile.html, for some food for thought )