-
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.
3344: Added lints `into_iter_on_ref` and `into_iter_on_array`. r=phansch a=kennytm Fixes #1565. `into_iter_on_array` is a correctness lint against `into_iter()` on `[T; n]` and `PathBuf` (please provide a concise noun that covers both types 🙃). `into_iter_on_ref` is a style lint against `into_iter()` on `&C` where `C` is `[T]`, `Vec<T>`, `BTreeSet<T>` etc. Both suggests replacing the `into_iter()` with `iter()` or `iter_mut()`. `into_iter_on_array` is a correctness lint since it is very likely the standard library would provide an `into_iter()` method for `[T; n]` (rust-lang/rust#25725) and existing type inference of `[a, b, c].into_iter()` will be broken. `PathBuf` is also placed under this lint since `PathBuf::into_iter` currently doesn't exist and it makes some sense to implement `IntoIterator` on it yielding `OsString`s. Co-authored-by: kennytm <kennytm@gmail.com>
- Loading branch information
Showing
8 changed files
with
350 additions
and
7 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
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,44 @@ | ||
#![warn(clippy::into_iter_on_ref)] | ||
#![deny(clippy::into_iter_on_array)] | ||
|
||
struct X; | ||
use std::collections::*; | ||
|
||
fn main() { | ||
for _ in &[1,2,3] {} | ||
for _ in vec![X, X] {} | ||
for _ in &vec![X, X] {} | ||
for _ in [1,2,3].into_iter() {} //~ ERROR equivalent to .iter() | ||
|
||
let _ = [1,2,3].into_iter(); //~ ERROR equivalent to .iter() | ||
let _ = vec![1,2,3].into_iter(); | ||
let _ = (&vec![1,2,3]).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = vec![1,2,3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() | ||
let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ||
|
||
let _ = (&&&&&&&[1,2,3]).into_iter(); //~ ERROR equivalent to .iter() | ||
let _ = (&&&&mut &&&[1,2,3]).into_iter(); //~ ERROR equivalent to .iter() | ||
let _ = (&mut &mut &mut [1,2,3]).into_iter(); //~ ERROR equivalent to .iter_mut() | ||
|
||
let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ||
let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ||
|
||
let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = (&HashSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter() | ||
let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() | ||
let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() | ||
} |
Oops, something went wrong.