fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2// aux-build:external_unsafe_macro.rs 3 4#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE 5 6extern crate external_unsafe_macro; 7 8unsafe fn unsf() {} 9 10pub unsafe fn foo() { unsafe { 11 //~^ NOTE an unsafe function restricts its caller, but its body is safe by default 12 unsf(); //~ ERROR call to unsafe function is unsafe 13 //~^ NOTE 14 //~| NOTE 15 unsf(); //~ ERROR call to unsafe function is unsafe 16 //~^ NOTE 17 //~| NOTE 18}} 19 20pub unsafe fn bar(x: *const i32) -> i32 { unsafe { 21 //~^ NOTE an unsafe function restricts its caller, but its body is safe by default 22 let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block 23 //~^ NOTE 24 //~| NOTE 25 y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block 26 //~^ NOTE 27 //~| NOTE 28}} 29 30static mut BAZ: i32 = 0; 31pub unsafe fn baz() -> i32 { unsafe { 32 //~^ NOTE an unsafe function restricts its caller, but its body is safe by default 33 let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block 34 //~^ NOTE 35 //~| NOTE 36 y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block 37 //~^ NOTE 38 //~| NOTE 39}} 40 41macro_rules! unsafe_macro { () => (unsf()) } 42//~^ ERROR call to unsafe function is unsafe 43//~| NOTE 44//~| NOTE 45//~| ERROR call to unsafe function is unsafe 46//~| NOTE 47//~| NOTE 48 49pub unsafe fn unsafe_in_macro() { unsafe { 50 //~^ NOTE an unsafe function restricts its caller, but its body is safe by default 51 unsafe_macro!(); 52 //~^ NOTE 53 //~| NOTE 54 unsafe_macro!(); 55 //~^ NOTE 56 //~| NOTE 57}} 58 59pub unsafe fn unsafe_in_external_macro() { 60 // FIXME: https://github.com/rust-lang/rust/issues/112504 61 // FIXME: ~^ NOTE an unsafe function restricts its caller, but its body is safe by default 62 external_unsafe_macro::unsafe_macro!(); 63 external_unsafe_macro::unsafe_macro!(); 64} 65 66fn main() {}