From 256b6419762e662c5d9e6e7e41241b6bb9110e9f Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sun, 13 Jan 2019 12:52:51 +0100 Subject: [PATCH] Add run-rustfix to into_iter_on_ref --- tests/ui/into_iter_on_ref.fixed | 46 +++++++++++++++++++++++++ tests/ui/into_iter_on_ref.rs | 2 ++ tests/ui/into_iter_on_ref.stderr | 58 ++++++++++++++++---------------- 3 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 tests/ui/into_iter_on_ref.fixed diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed new file mode 100644 index 00000000000..f5342be631b --- /dev/null +++ b/tests/ui/into_iter_on_ref.fixed @@ -0,0 +1,46 @@ +// run-rustfix +#![allow(clippy::useless_vec)] +#![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].iter() {} //~ ERROR equivalent to .iter() + + let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter() + let _ = vec![1, 2, 3].into_iter(); + let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter() + let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter() + let _ = std::rc::Rc::from(&[X][..]).iter(); //~ WARN equivalent to .iter() + let _ = std::sync::Arc::from(&[X][..]).iter(); //~ WARN equivalent to .iter() + + let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter() + let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter() + let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR equivalent to .iter_mut() + + let _ = (&Some(4)).iter(); //~ WARN equivalent to .iter() + let _ = (&mut Some(5)).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&Ok::<_, i32>(6)).iter(); //~ WARN equivalent to .iter() + let _ = (&mut Err::(7)).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&Vec::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&mut Vec::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&BTreeMap::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&mut BTreeMap::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&VecDeque::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&mut VecDeque::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&LinkedList::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&mut LinkedList::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() + let _ = (&HashMap::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&mut HashMap::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() + + let _ = (&BTreeSet::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&BinaryHeap::::new()).iter(); //~ WARN equivalent to .iter() + let _ = (&HashSet::::new()).iter(); //~ WARN equivalent to .iter() + let _ = std::path::Path::new("12/34").iter(); //~ WARN equivalent to .iter() + let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR equivalent to .iter() +} diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 212234f0346..5ec64dcf733 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -1,3 +1,5 @@ +// run-rustfix +#![allow(clippy::useless_vec)] #![warn(clippy::into_iter_on_ref)] #![deny(clippy::into_iter_on_array)] diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index e7f2a21d7a4..931e4880f93 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,23 +1,23 @@ error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:11:24 + --> $DIR/into_iter_on_ref.rs:13:24 | LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` | note: lint level defined here - --> $DIR/into_iter_on_ref.rs:2:9 + --> $DIR/into_iter_on_ref.rs:4:9 | LL | #![deny(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:13:23 + --> $DIR/into_iter_on_ref.rs:15:23 | LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:15:30 + --> $DIR/into_iter_on_ref.rs:17:30 | LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` @@ -25,151 +25,151 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:16:46 + --> $DIR/into_iter_on_ref.rs:18:46 | LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:17:41 + --> $DIR/into_iter_on_ref.rs:19:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:18:44 + --> $DIR/into_iter_on_ref.rs:20:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:20:32 + --> $DIR/into_iter_on_ref.rs:22:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:21:36 + --> $DIR/into_iter_on_ref.rs:23:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the array - --> $DIR/into_iter_on_ref.rs:22:40 + --> $DIR/into_iter_on_ref.rs:24:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Option - --> $DIR/into_iter_on_ref.rs:24:24 + --> $DIR/into_iter_on_ref.rs:26:24 | LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Option - --> $DIR/into_iter_on_ref.rs:25:28 + --> $DIR/into_iter_on_ref.rs:27:28 | LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Result - --> $DIR/into_iter_on_ref.rs:26:32 + --> $DIR/into_iter_on_ref.rs:28:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Result - --> $DIR/into_iter_on_ref.rs:27:37 + --> $DIR/into_iter_on_ref.rs:29:37 | LL | let _ = (&mut Err::(7)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:28:34 + --> $DIR/into_iter_on_ref.rs:30:34 | LL | let _ = (&Vec::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:29:38 + --> $DIR/into_iter_on_ref.rs:31:38 | LL | let _ = (&mut Vec::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the BTreeMap - --> $DIR/into_iter_on_ref.rs:30:44 + --> $DIR/into_iter_on_ref.rs:32:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the BTreeMap - --> $DIR/into_iter_on_ref.rs:31:48 + --> $DIR/into_iter_on_ref.rs:33:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the VecDeque - --> $DIR/into_iter_on_ref.rs:32:39 + --> $DIR/into_iter_on_ref.rs:34:39 | LL | let _ = (&VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the VecDeque - --> $DIR/into_iter_on_ref.rs:33:43 + --> $DIR/into_iter_on_ref.rs:35:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the LinkedList - --> $DIR/into_iter_on_ref.rs:34:41 + --> $DIR/into_iter_on_ref.rs:36:41 | LL | let _ = (&LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the LinkedList - --> $DIR/into_iter_on_ref.rs:35:45 + --> $DIR/into_iter_on_ref.rs:37:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the HashMap - --> $DIR/into_iter_on_ref.rs:36:43 + --> $DIR/into_iter_on_ref.rs:38:43 | LL | let _ = (&HashMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the HashMap - --> $DIR/into_iter_on_ref.rs:37:47 + --> $DIR/into_iter_on_ref.rs:39:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the BTreeSet - --> $DIR/into_iter_on_ref.rs:39:39 + --> $DIR/into_iter_on_ref.rs:41:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the BinaryHeap - --> $DIR/into_iter_on_ref.rs:40:41 + --> $DIR/into_iter_on_ref.rs:42:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the HashSet - --> $DIR/into_iter_on_ref.rs:41:38 + --> $DIR/into_iter_on_ref.rs:43:38 | LL | let _ = (&HashSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the Path - --> $DIR/into_iter_on_ref.rs:42:43 + --> $DIR/into_iter_on_ref.rs:44:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the PathBuf - --> $DIR/into_iter_on_ref.rs:43:47 + --> $DIR/into_iter_on_ref.rs:45:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter`