1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//@ run-rustfix
//@ aux-build:external_unsafe_macro.rs
#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE
#![crate_name = "wrapping_unsafe_block_sugg"]
extern crate external_unsafe_macro;
unsafe fn unsf() {}
pub unsafe fn foo() { unsafe {
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
//~^ NOTE call to unsafe function
//~| NOTE for more information, see
//~| NOTE consult the function's documentation
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
//~^ NOTE call to unsafe function
//~| NOTE for more information, see
//~| NOTE consult the function's documentation
}}
pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
//~^ NOTE dereference of raw pointer
//~| NOTE for more information, see
//~| NOTE raw pointers may be null
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
//~^ NOTE dereference of raw pointer
//~| NOTE for more information, see
//~| NOTE raw pointers may be null
}}
static mut BAZ: i32 = 0;
pub unsafe fn baz() -> i32 { unsafe {
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
//~^ NOTE use of mutable static
//~| NOTE for more information, see
//~| NOTE mutable statics can be mutated by multiple threads
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
//~^ NOTE use of mutable static
//~| NOTE for more information, see
//~| NOTE mutable statics can be mutated by multiple threads
}}
macro_rules! unsafe_macro { () => (unsf()) }
//~^ ERROR call to unsafe function `unsf` is unsafe
//~| NOTE call to unsafe function
//~| NOTE for more information, see
//~| NOTE consult the function's documentation
//~| ERROR call to unsafe function `unsf` is unsafe
//~| NOTE call to unsafe function
//~| NOTE for more information, see
//~| NOTE consult the function's documentation
pub unsafe fn unsafe_in_macro() { unsafe {
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
unsafe_macro!();
//~^ NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
unsafe_macro!();
//~^ NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
}}
pub unsafe fn unsafe_in_external_macro() {
// FIXME: https://github.com/rust-lang/rust/issues/112504
// FIXME: ~^ NOTE an unsafe function restricts its caller, but its body is safe by default
external_unsafe_macro::unsafe_macro!();
external_unsafe_macro::unsafe_macro!();
}
fn main() {}
|