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 11#![ feature( unsafe_block_in_unsafe_fn) ]
22#![ warn( unsafe_op_in_unsafe_fn) ]
33#![ deny( unused_unsafe) ]
4+ #![ deny( safe_packed_borrows) ]
45
56unsafe 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
717unsafe 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
1228unsafe fn bar ( ) {
13- unsafe { unsf ( ) } // no error
29+ // no error
30+ unsafe {
31+ unsf ( ) ;
32+ * PTR ;
33+ VOID = ( ) ;
34+ & PACKED . data ;
35+ }
1436}
1537
1638unsafe fn baz ( ) {
@@ -20,7 +42,11 @@ unsafe fn baz() {
2042
2143#[ allow( unsafe_op_in_unsafe_fn) ]
2244unsafe 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
You can’t perform that action at this time.
0 commit comments