-
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.
unnecessary_clone: split rustfixable lint out into separate test
- Loading branch information
1 parent
362d0c8
commit 218f8bf
Showing
5 changed files
with
77 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// run-rustfix | ||
|
||
#![allow(unused)] | ||
|
||
use std::collections::HashSet; | ||
use std::collections::VecDeque; | ||
|
||
fn main() { | ||
let v = [1, 2, 3, 4, 5]; | ||
let v2: Vec<isize> = v.to_vec(); | ||
let v3: HashSet<isize> = v.iter().cloned().collect(); | ||
let v4: VecDeque<isize> = v.iter().cloned().collect(); | ||
|
||
// Handle macro expansion in suggestion | ||
let _: Vec<isize> = vec![1, 2, 3].to_vec(); | ||
|
||
// Issue #3704 | ||
unsafe { | ||
let _: Vec<u8> = std::ffi::CStr::from_ptr(std::ptr::null()) | ||
.to_bytes().to_vec(); | ||
} | ||
} |
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,25 @@ | ||
// run-rustfix | ||
|
||
#![allow(unused)] | ||
|
||
use std::collections::HashSet; | ||
use std::collections::VecDeque; | ||
|
||
fn main() { | ||
let v = [1, 2, 3, 4, 5]; | ||
let v2: Vec<isize> = v.iter().cloned().collect(); | ||
let v3: HashSet<isize> = v.iter().cloned().collect(); | ||
let v4: VecDeque<isize> = v.iter().cloned().collect(); | ||
|
||
// Handle macro expansion in suggestion | ||
let _: Vec<isize> = vec![1, 2, 3].iter().cloned().collect(); | ||
|
||
// Issue #3704 | ||
unsafe { | ||
let _: Vec<u8> = std::ffi::CStr::from_ptr(std::ptr::null()) | ||
.to_bytes() | ||
.iter() | ||
.cloned() | ||
.collect(); | ||
} | ||
} |
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,26 @@ | ||
error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable | ||
--> $DIR/iter_cloned_collect.rs:10:27 | ||
| | ||
LL | let v2: Vec<isize> = v.iter().cloned().collect(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` | ||
| | ||
= note: `-D clippy::iter-cloned-collect` implied by `-D warnings` | ||
|
||
error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable | ||
--> $DIR/iter_cloned_collect.rs:15:38 | ||
| | ||
LL | let _: Vec<isize> = vec![1, 2, 3].iter().cloned().collect(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` | ||
|
||
error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable | ||
--> $DIR/iter_cloned_collect.rs:20:24 | ||
| | ||
LL | .to_bytes() | ||
| ________________________^ | ||
LL | | .iter() | ||
LL | | .cloned() | ||
LL | | .collect(); | ||
| |______________________^ help: try: `.to_vec()` | ||
|
||
error: aborting due to 3 previous errors | ||
|
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