-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4599 - lzutao:zero-ptr-suggestion, r=flip1995
Add suggestion for zero-ptr lint changelog: Improve suggestion of `zero_ptr` lint
- Loading branch information
Showing
5 changed files
with
69 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-rustfix | ||
pub fn foo(_const: *const f32, _mut: *mut i64) {} | ||
|
||
fn main() { | ||
let _ = std::ptr::null::<usize>(); | ||
let _ = std::ptr::null_mut::<f64>(); | ||
let _: *const u8 = std::ptr::null(); | ||
|
||
foo(0 as _, 0 as _); | ||
foo(std::ptr::null(), std::ptr::null_mut()); | ||
|
||
let z = 0; | ||
let _ = z as *const usize; // this is currently not caught | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
#[allow(unused_variables)] | ||
// run-rustfix | ||
pub fn foo(_const: *const f32, _mut: *mut i64) {} | ||
|
||
fn main() { | ||
let x = 0 as *const usize; | ||
let y = 0 as *mut f64; | ||
let _ = 0 as *const usize; | ||
let _ = 0 as *mut f64; | ||
let _: *const u8 = 0 as *const _; | ||
|
||
foo(0 as _, 0 as _); | ||
foo(0 as *const _, 0 as *mut _); | ||
|
||
let z = 0; | ||
let z = z as *const usize; // this is currently not caught | ||
let _ = z as *const usize; // this is currently not caught | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
error: `0 as *const _` detected. Consider using `ptr::null()` | ||
--> $DIR/zero_ptr.rs:3:13 | ||
error: `0 as *const _` detected | ||
--> $DIR/zero_ptr.rs:5:13 | ||
| | ||
LL | let x = 0 as *const usize; | ||
| ^^^^^^^^^^^^^^^^^ | ||
LL | let _ = 0 as *const usize; | ||
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null::<usize>()` | ||
| | ||
= note: `-D clippy::zero-ptr` implied by `-D warnings` | ||
|
||
error: `0 as *mut _` detected. Consider using `ptr::null_mut()` | ||
--> $DIR/zero_ptr.rs:4:13 | ||
error: `0 as *mut _` detected | ||
--> $DIR/zero_ptr.rs:6:13 | ||
| | ||
LL | let y = 0 as *mut f64; | ||
| ^^^^^^^^^^^^^ | ||
LL | let _ = 0 as *mut f64; | ||
| ^^^^^^^^^^^^^ help: try: `std::ptr::null_mut::<f64>()` | ||
|
||
error: aborting due to 2 previous errors | ||
error: `0 as *const _` detected | ||
--> $DIR/zero_ptr.rs:7:24 | ||
| | ||
LL | let _: *const u8 = 0 as *const _; | ||
| ^^^^^^^^^^^^^ help: try: `std::ptr::null()` | ||
|
||
error: `0 as *const _` detected | ||
--> $DIR/zero_ptr.rs:10:9 | ||
| | ||
LL | foo(0 as *const _, 0 as *mut _); | ||
| ^^^^^^^^^^^^^ help: try: `std::ptr::null()` | ||
|
||
error: `0 as *mut _` detected | ||
--> $DIR/zero_ptr.rs:10:24 | ||
| | ||
LL | foo(0 as *const _, 0 as *mut _); | ||
| ^^^^^^^^^^^ help: try: `std::ptr::null_mut()` | ||
|
||
error: aborting due to 5 previous errors | ||
|