Skip to content

Commit 256b641

Browse files
committed
Add run-rustfix to into_iter_on_ref
1 parent 787f5a2 commit 256b641

File tree

3 files changed

+77
-29
lines changed

3 files changed

+77
-29
lines changed

tests/ui/into_iter_on_ref.fixed

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// run-rustfix
2+
#![allow(clippy::useless_vec)]
3+
#![warn(clippy::into_iter_on_ref)]
4+
#![deny(clippy::into_iter_on_array)]
5+
6+
struct X;
7+
use std::collections::*;
8+
9+
fn main() {
10+
for _ in &[1, 2, 3] {}
11+
for _ in vec![X, X] {}
12+
for _ in &vec![X, X] {}
13+
for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
14+
15+
let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
16+
let _ = vec![1, 2, 3].into_iter();
17+
let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter()
18+
let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter()
19+
let _ = std::rc::Rc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
20+
let _ = std::sync::Arc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
21+
22+
let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
23+
let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
24+
let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR equivalent to .iter_mut()
25+
26+
let _ = (&Some(4)).iter(); //~ WARN equivalent to .iter()
27+
let _ = (&mut Some(5)).iter_mut(); //~ WARN equivalent to .iter_mut()
28+
let _ = (&Ok::<_, i32>(6)).iter(); //~ WARN equivalent to .iter()
29+
let _ = (&mut Err::<i32, _>(7)).iter_mut(); //~ WARN equivalent to .iter_mut()
30+
let _ = (&Vec::<i32>::new()).iter(); //~ WARN equivalent to .iter()
31+
let _ = (&mut Vec::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
32+
let _ = (&BTreeMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
33+
let _ = (&mut BTreeMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
34+
let _ = (&VecDeque::<i32>::new()).iter(); //~ WARN equivalent to .iter()
35+
let _ = (&mut VecDeque::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
36+
let _ = (&LinkedList::<i32>::new()).iter(); //~ WARN equivalent to .iter()
37+
let _ = (&mut LinkedList::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
38+
let _ = (&HashMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
39+
let _ = (&mut HashMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
40+
41+
let _ = (&BTreeSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
42+
let _ = (&BinaryHeap::<i32>::new()).iter(); //~ WARN equivalent to .iter()
43+
let _ = (&HashSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
44+
let _ = std::path::Path::new("12/34").iter(); //~ WARN equivalent to .iter()
45+
let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR equivalent to .iter()
46+
}

tests/ui/into_iter_on_ref.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
#![allow(clippy::useless_vec)]
13
#![warn(clippy::into_iter_on_ref)]
24
#![deny(clippy::into_iter_on_array)]
35

tests/ui/into_iter_on_ref.stderr

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,175 @@
11
error: this .into_iter() call is equivalent to .iter() and will not move the array
2-
--> $DIR/into_iter_on_ref.rs:11:24
2+
--> $DIR/into_iter_on_ref.rs:13:24
33
|
44
LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
55
| ^^^^^^^^^ help: call directly: `iter`
66
|
77
note: lint level defined here
8-
--> $DIR/into_iter_on_ref.rs:2:9
8+
--> $DIR/into_iter_on_ref.rs:4:9
99
|
1010
LL | #![deny(clippy::into_iter_on_array)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: this .into_iter() call is equivalent to .iter() and will not move the array
14-
--> $DIR/into_iter_on_ref.rs:13:23
14+
--> $DIR/into_iter_on_ref.rs:15:23
1515
|
1616
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
1717
| ^^^^^^^^^ help: call directly: `iter`
1818

1919
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
20-
--> $DIR/into_iter_on_ref.rs:15:30
20+
--> $DIR/into_iter_on_ref.rs:17:30
2121
|
2222
LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
2323
| ^^^^^^^^^ help: call directly: `iter`
2424
|
2525
= note: `-D clippy::into-iter-on-ref` implied by `-D warnings`
2626

2727
error: this .into_iter() call is equivalent to .iter() and will not move the slice
28-
--> $DIR/into_iter_on_ref.rs:16:46
28+
--> $DIR/into_iter_on_ref.rs:18:46
2929
|
3030
LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter()
3131
| ^^^^^^^^^ help: call directly: `iter`
3232

3333
error: this .into_iter() call is equivalent to .iter() and will not move the slice
34-
--> $DIR/into_iter_on_ref.rs:17:41
34+
--> $DIR/into_iter_on_ref.rs:19:41
3535
|
3636
LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
3737
| ^^^^^^^^^ help: call directly: `iter`
3838

3939
error: this .into_iter() call is equivalent to .iter() and will not move the slice
40-
--> $DIR/into_iter_on_ref.rs:18:44
40+
--> $DIR/into_iter_on_ref.rs:20:44
4141
|
4242
LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
4343
| ^^^^^^^^^ help: call directly: `iter`
4444

4545
error: this .into_iter() call is equivalent to .iter() and will not move the array
46-
--> $DIR/into_iter_on_ref.rs:20:32
46+
--> $DIR/into_iter_on_ref.rs:22:32
4747
|
4848
LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
4949
| ^^^^^^^^^ help: call directly: `iter`
5050

5151
error: this .into_iter() call is equivalent to .iter() and will not move the array
52-
--> $DIR/into_iter_on_ref.rs:21:36
52+
--> $DIR/into_iter_on_ref.rs:23:36
5353
|
5454
LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
5555
| ^^^^^^^^^ help: call directly: `iter`
5656

5757
error: this .into_iter() call is equivalent to .iter_mut() and will not move the array
58-
--> $DIR/into_iter_on_ref.rs:22:40
58+
--> $DIR/into_iter_on_ref.rs:24:40
5959
|
6060
LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut()
6161
| ^^^^^^^^^ help: call directly: `iter_mut`
6262

6363
error: this .into_iter() call is equivalent to .iter() and will not move the Option
64-
--> $DIR/into_iter_on_ref.rs:24:24
64+
--> $DIR/into_iter_on_ref.rs:26:24
6565
|
6666
LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter()
6767
| ^^^^^^^^^ help: call directly: `iter`
6868

6969
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Option
70-
--> $DIR/into_iter_on_ref.rs:25:28
70+
--> $DIR/into_iter_on_ref.rs:27:28
7171
|
7272
LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut()
7373
| ^^^^^^^^^ help: call directly: `iter_mut`
7474

7575
error: this .into_iter() call is equivalent to .iter() and will not move the Result
76-
--> $DIR/into_iter_on_ref.rs:26:32
76+
--> $DIR/into_iter_on_ref.rs:28:32
7777
|
7878
LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter()
7979
| ^^^^^^^^^ help: call directly: `iter`
8080

8181
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Result
82-
--> $DIR/into_iter_on_ref.rs:27:37
82+
--> $DIR/into_iter_on_ref.rs:29:37
8383
|
8484
LL | let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ WARN equivalent to .iter_mut()
8585
| ^^^^^^^^^ help: call directly: `iter_mut`
8686

8787
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
88-
--> $DIR/into_iter_on_ref.rs:28:34
88+
--> $DIR/into_iter_on_ref.rs:30:34
8989
|
9090
LL | let _ = (&Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
9191
| ^^^^^^^^^ help: call directly: `iter`
9292

9393
error: this .into_iter() call is equivalent to .iter_mut() and will not move the Vec
94-
--> $DIR/into_iter_on_ref.rs:29:38
94+
--> $DIR/into_iter_on_ref.rs:31:38
9595
|
9696
LL | let _ = (&mut Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
9797
| ^^^^^^^^^ help: call directly: `iter_mut`
9898

9999
error: this .into_iter() call is equivalent to .iter() and will not move the BTreeMap
100-
--> $DIR/into_iter_on_ref.rs:30:44
100+
--> $DIR/into_iter_on_ref.rs:32:44
101101
|
102102
LL | let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
103103
| ^^^^^^^^^ help: call directly: `iter`
104104

105105
error: this .into_iter() call is equivalent to .iter_mut() and will not move the BTreeMap
106-
--> $DIR/into_iter_on_ref.rs:31:48
106+
--> $DIR/into_iter_on_ref.rs:33:48
107107
|
108108
LL | let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
109109
| ^^^^^^^^^ help: call directly: `iter_mut`
110110

111111
error: this .into_iter() call is equivalent to .iter() and will not move the VecDeque
112-
--> $DIR/into_iter_on_ref.rs:32:39
112+
--> $DIR/into_iter_on_ref.rs:34:39
113113
|
114114
LL | let _ = (&VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
115115
| ^^^^^^^^^ help: call directly: `iter`
116116

117117
error: this .into_iter() call is equivalent to .iter_mut() and will not move the VecDeque
118-
--> $DIR/into_iter_on_ref.rs:33:43
118+
--> $DIR/into_iter_on_ref.rs:35:43
119119
|
120120
LL | let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
121121
| ^^^^^^^^^ help: call directly: `iter_mut`
122122

123123
error: this .into_iter() call is equivalent to .iter() and will not move the LinkedList
124-
--> $DIR/into_iter_on_ref.rs:34:41
124+
--> $DIR/into_iter_on_ref.rs:36:41
125125
|
126126
LL | let _ = (&LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
127127
| ^^^^^^^^^ help: call directly: `iter`
128128

129129
error: this .into_iter() call is equivalent to .iter_mut() and will not move the LinkedList
130-
--> $DIR/into_iter_on_ref.rs:35:45
130+
--> $DIR/into_iter_on_ref.rs:37:45
131131
|
132132
LL | let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
133133
| ^^^^^^^^^ help: call directly: `iter_mut`
134134

135135
error: this .into_iter() call is equivalent to .iter() and will not move the HashMap
136-
--> $DIR/into_iter_on_ref.rs:36:43
136+
--> $DIR/into_iter_on_ref.rs:38:43
137137
|
138138
LL | let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
139139
| ^^^^^^^^^ help: call directly: `iter`
140140

141141
error: this .into_iter() call is equivalent to .iter_mut() and will not move the HashMap
142-
--> $DIR/into_iter_on_ref.rs:37:47
142+
--> $DIR/into_iter_on_ref.rs:39:47
143143
|
144144
LL | let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
145145
| ^^^^^^^^^ help: call directly: `iter_mut`
146146

147147
error: this .into_iter() call is equivalent to .iter() and will not move the BTreeSet
148-
--> $DIR/into_iter_on_ref.rs:39:39
148+
--> $DIR/into_iter_on_ref.rs:41:39
149149
|
150150
LL | let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
151151
| ^^^^^^^^^ help: call directly: `iter`
152152

153153
error: this .into_iter() call is equivalent to .iter() and will not move the BinaryHeap
154-
--> $DIR/into_iter_on_ref.rs:40:41
154+
--> $DIR/into_iter_on_ref.rs:42:41
155155
|
156156
LL | let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
157157
| ^^^^^^^^^ help: call directly: `iter`
158158

159159
error: this .into_iter() call is equivalent to .iter() and will not move the HashSet
160-
--> $DIR/into_iter_on_ref.rs:41:38
160+
--> $DIR/into_iter_on_ref.rs:43:38
161161
|
162162
LL | let _ = (&HashSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
163163
| ^^^^^^^^^ help: call directly: `iter`
164164

165165
error: this .into_iter() call is equivalent to .iter() and will not move the Path
166-
--> $DIR/into_iter_on_ref.rs:42:43
166+
--> $DIR/into_iter_on_ref.rs:44:43
167167
|
168168
LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter()
169169
| ^^^^^^^^^ help: call directly: `iter`
170170

171171
error: this .into_iter() call is equivalent to .iter() and will not move the PathBuf
172-
--> $DIR/into_iter_on_ref.rs:43:47
172+
--> $DIR/into_iter_on_ref.rs:45:47
173173
|
174174
LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
175175
| ^^^^^^^^^ help: call directly: `iter`

0 commit comments

Comments
 (0)