]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggest-null-ptr.rs
Rollup merge of #100599 - MatthewPeterKelly:add-E0523-description-and-test, r=compile...
[rust.git] / tests / ui / suggest-null-ptr.rs
1 // run-rustfix
2
3 // Suggest providing a std::ptr::null{,_mut}() to a function that takes in a raw
4 // pointer if a literal 0 was provided by the user.
5
6 extern "C" {
7     fn foo(ptr: *const u8);
8
9     fn foo_mut(ptr: *mut u8);
10
11     fn usize(ptr: *const usize);
12
13     fn usize_mut(ptr: *mut usize);
14 }
15
16 fn main() {
17     unsafe {
18         foo(0);
19         //~^ mismatched types [E0308]
20         //~| if you meant to create a null pointer, use `std::ptr::null()`
21         foo_mut(0);
22         //~^ mismatched types [E0308]
23         //~| if you meant to create a null pointer, use `std::ptr::null_mut()`
24         usize(0);
25         //~^ mismatched types [E0308]
26         //~| if you meant to create a null pointer, use `std::ptr::null()`
27         usize_mut(0);
28         //~^ mismatched types [E0308]
29         //~| if you meant to create a null pointer, use `std::ptr::null_mut()`
30     }
31 }