]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggest-null-ptr.fixed
Rollup merge of #107700 - jyn514:tools-builder, r=Mark-Simulacrum
[rust.git] / tests / ui / suggest-null-ptr.fixed
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(std::ptr::null());
19         //~^ mismatched types [E0308]
20         //~| if you meant to create a null pointer, use `std::ptr::null()`
21         foo_mut(std::ptr::null_mut());
22         //~^ mismatched types [E0308]
23         //~| if you meant to create a null pointer, use `std::ptr::null_mut()`
24         usize(std::ptr::null());
25         //~^ mismatched types [E0308]
26         //~| if you meant to create a null pointer, use `std::ptr::null()`
27         usize_mut(std::ptr::null_mut());
28         //~^ mismatched types [E0308]
29         //~| if you meant to create a null pointer, use `std::ptr::null_mut()`
30     }
31 }