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 //~^ ERROR call to unsafe function is unsafe and requires unsafe block
15 //~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
17 //~^ ERROR use of mutable static is unsafe and requires unsafe block
20 //~^ ERROR unnecessary `unsafe` block
23 // Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
24 #[warn(unsafe_op_in_unsafe_fn)]
26 unsafe fn warning_level() {
28 //~^ ERROR call to unsafe function is unsafe and requires unsafe block
30 //~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
32 //~^ ERROR use of mutable static is unsafe and requires unsafe block
34 //~^ ERROR unnecessary `unsafe` block
37 unsafe fn explicit_block() {
46 unsafe fn two_explicit_blocks() {
47 unsafe { unsafe { unsf() } }
48 //~^ ERROR unnecessary `unsafe` block
51 #[allow(unsafe_op_in_unsafe_fn)]
52 unsafe fn allow_level() {
53 // lint allowed -> no error
59 //~^ ERROR unnecessary `unsafe` block
62 unsafe fn nested_allow_level() {
63 #[allow(unsafe_op_in_unsafe_fn)]
65 // lint allowed -> no error
71 //~^ ERROR unnecessary `unsafe` block
77 //~^ ERROR call to unsafe function is unsafe and requires unsafe block
78 #[allow(unsafe_op_in_unsafe_fn)]
81 //~^ ERROR call to unsafe function is unsafe and requires unsafe function or block