Skip to content

Commit 3ce9d5c

Browse files
Add more cases to the test
1 parent bb67915 commit 3ce9d5c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
#![feature(unsafe_block_in_unsafe_fn)]
22
#![warn(unsafe_op_in_unsafe_fn)]
33
#![deny(unused_unsafe)]
4+
#![deny(safe_packed_borrows)]
45

56
unsafe fn unsf() {}
7+
const PTR: *const () = std::ptr::null();
8+
static mut VOID: () = ();
9+
10+
#[repr(packed)]
11+
pub struct Packed {
12+
data: &'static u32,
13+
}
14+
15+
const PACKED: Packed = Packed { data: &0 };
616

717
unsafe fn foo() {
818
unsf();
919
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
20+
*PTR;
21+
//~^ WARNING dereference of raw pointer is unsafe and requires unsafe block
22+
VOID = ();
23+
//~^ WARNING use of mutable static is unsafe and requires unsafe block
24+
&PACKED.data; // the level for the `safe_packed_borrows` lint is ignored
25+
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
1026
}
1127

1228
unsafe fn bar() {
13-
unsafe { unsf() } // no error
29+
// no error
30+
unsafe {
31+
unsf();
32+
*PTR;
33+
VOID = ();
34+
&PACKED.data;
35+
}
1436
}
1537

1638
unsafe fn baz() {
@@ -20,7 +42,11 @@ unsafe fn baz() {
2042

2143
#[allow(unsafe_op_in_unsafe_fn)]
2244
unsafe fn qux() {
23-
unsf(); // no error
45+
// lint allowed -> no error
46+
unsf();
47+
*PTR;
48+
VOID = ();
49+
&PACKED.data;
2450

2551
unsafe { unsf() }
2652
//~^ ERROR unnecessary `unsafe` block

0 commit comments

Comments
 (0)