-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changelog: [`cmp_null`]: add autofix
- Loading branch information
Showing
4 changed files
with
86 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![warn(clippy::cmp_null)] | ||
#![allow(unused_mut)] | ||
|
||
use std::ptr; | ||
|
||
fn main() { | ||
let x = 0; | ||
let p: *const usize = &x; | ||
if p.is_null() { | ||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method | ||
//~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` | ||
println!("This is surprising!"); | ||
} | ||
if p.is_null() { | ||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method | ||
println!("This is surprising!"); | ||
} | ||
|
||
let mut y = 0; | ||
let mut m: *mut usize = &mut y; | ||
if m.is_null() { | ||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method | ||
println!("This is surprising, too!"); | ||
} | ||
if m.is_null() { | ||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method | ||
println!("This is surprising, too!"); | ||
} | ||
|
||
let _ = (x as *const ()).is_null(); | ||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method | ||
} |
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