File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( unsafe_block_in_unsafe_fn) ]
2
2
#![ warn( unsafe_op_in_unsafe_fn) ]
3
3
#![ deny( unused_unsafe) ]
4
+ #![ deny( safe_packed_borrows) ]
4
5
5
6
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 } ;
6
16
7
17
unsafe fn foo ( ) {
8
18
unsf ( ) ;
9
19
//~^ 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
10
26
}
11
27
12
28
unsafe fn bar ( ) {
13
- unsafe { unsf ( ) } // no error
29
+ // no error
30
+ unsafe {
31
+ unsf ( ) ;
32
+ * PTR ;
33
+ VOID = ( ) ;
34
+ & PACKED . data ;
35
+ }
14
36
}
15
37
16
38
unsafe fn baz ( ) {
@@ -20,7 +42,11 @@ unsafe fn baz() {
20
42
21
43
#[ allow( unsafe_op_in_unsafe_fn) ]
22
44
unsafe fn qux ( ) {
23
- unsf ( ) ; // no error
45
+ // lint allowed -> no error
46
+ unsf ( ) ;
47
+ * PTR ;
48
+ VOID = ( ) ;
49
+ & PACKED . data ;
24
50
25
51
unsafe { unsf ( ) }
26
52
//~^ ERROR unnecessary `unsafe` block
You can’t perform that action at this time.
0 commit comments