This compliant example requires the caller to wrap the macro invocation in an unsafe block,
making the use of unsafe code obvious at the call site.
Visibility can be further improved by prefixing the identifier for each unsafe macro with the string unsafe_.
miri
// This macro requires the caller to acknowledge the unsafe operation - compliant
macro_rules! unsafe_deref_ptr {
($ptr:expr) => {
*$ptr
};
}
fn main() {
let x = 42;
let ptr = &x as *const i32;
// The unsafe operation is visible at the call site
let val = unsafe { unsafe_deref_ptr!(ptr) };
println!("val = {}", val);
}
|