1 // test the deref_nullptr lint
3 #![deny(deref_nullptr)]
14 let ub = *(a as *const i32);
15 let ub = *(0 as *const i32);
16 //~^ ERROR dereferencing a null pointer
17 let ub = *ptr::null::<i32>();
18 //~^ ERROR dereferencing a null pointer
19 let ub = *ptr::null_mut::<i32>();
20 //~^ ERROR dereferencing a null pointer
21 let ub = *(ptr::null::<i16>() as *const i32);
22 //~^ ERROR dereferencing a null pointer
23 let ub = *(ptr::null::<i16>() as *mut i32 as *mut usize as *const u8);
24 //~^ ERROR dereferencing a null pointer
25 let ub = &*ptr::null::<i32>();
26 //~^ ERROR dereferencing a null pointer
27 let ub = &*ptr::null_mut::<i32>();
28 //~^ ERROR dereferencing a null pointer
29 ptr::addr_of!(*ptr::null::<i32>());
30 //~^ ERROR dereferencing a null pointer
31 ptr::addr_of_mut!(*ptr::null_mut::<i32>());
32 //~^ ERROR dereferencing a null pointer
33 let offset = ptr::addr_of!((*ptr::null::<Struct>()).field);
34 //~^ ERROR dereferencing a null pointer