-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added checks for binary expr and added different test cases for unfix…
…able cases
- Loading branch information
1 parent
c6c7408
commit d43acb8
Showing
6 changed files
with
115 additions
and
109 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
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,20 @@ | ||
#![warn(clippy::non_zero_suggestions)] | ||
//@no-rustfix | ||
use std::num::{NonZeroI16, NonZeroI8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}; | ||
|
||
fn main() { | ||
let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); | ||
//~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
|
||
let n = NonZeroU32::new(20).unwrap(); | ||
let y = u64::from(n.get()); | ||
//~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
some_fn_that_only_takes_u64(y); | ||
} | ||
|
||
fn return_non_zero(x: u64, y: NonZeroU32) -> u64 { | ||
u64::from(y.get()) | ||
//~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
} | ||
|
||
fn some_fn_that_only_takes_u64(_: u64) {} |
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,23 @@ | ||
error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
--> tests/ui/non_zero_suggestions_unfixable.rs:6:18 | ||
| | ||
LL | let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(NonZeroU32::new(5).unwrap())` | ||
| | ||
= note: `-D clippy::non-zero-suggestions` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::non_zero_suggestions)]` | ||
|
||
error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
--> tests/ui/non_zero_suggestions_unfixable.rs:10:13 | ||
| | ||
LL | let y = u64::from(n.get()); | ||
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(n)` | ||
|
||
error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion | ||
--> tests/ui/non_zero_suggestions_unfixable.rs:16:5 | ||
| | ||
LL | u64::from(y.get()) | ||
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` | ||
|
||
error: aborting due to 3 previous errors | ||
|