2 // [thir]compile-flags: -Zthir-unsafeck
4 #![deny(unsafe_op_in_unsafe_fn)]
5 #![deny(unused_unsafe)]
8 const PTR: *const () = std::ptr::null();
9 static mut VOID: () = ();
11 unsafe fn deny_level() {
13 //[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
14 //[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
16 //~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
18 //~^ ERROR use of mutable static is unsafe and requires unsafe block
21 //~^ ERROR unnecessary `unsafe` block
24 // Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
25 #[warn(unsafe_op_in_unsafe_fn)]
27 unsafe fn warning_level() {
29 //[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
30 //[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
32 //~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
34 //~^ ERROR use of mutable static is unsafe and requires unsafe block
36 //~^ ERROR unnecessary `unsafe` block
39 unsafe fn explicit_block() {
48 unsafe fn two_explicit_blocks() {
49 unsafe { unsafe { unsf() } }
50 //~^ ERROR unnecessary `unsafe` block
53 #[allow(unsafe_op_in_unsafe_fn)]
54 unsafe fn allow_level() {
55 // lint allowed -> no error
63 unsafe fn nested_allow_level() {
64 #[allow(unsafe_op_in_unsafe_fn)]
66 // lint allowed -> no error
77 //[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
78 //[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
79 #[allow(unsafe_op_in_unsafe_fn)]
82 //[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
83 //[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe function or block