Skip to content

Commit aca5672

Browse files
committed
1 parent 345ac82 commit aca5672

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

clippy_lints/src/utils/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use rustc::ty::{
3939
subst::Kind,
4040
Binder, Ty, TyCtxt,
4141
};
42-
use rustc_data_structures::sync::Lrc;
4342
use rustc_errors::Applicability;
43+
use smallvec::SmallVec;
4444
use syntax::ast::{self, LitKind};
4545
use syntax::attr;
4646
use syntax::ext::hygiene::ExpnFormat;
@@ -248,7 +248,8 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)
248248
None => return None,
249249
};
250250

251-
for item in mem::replace(&mut items, Lrc::new(vec![])).iter() {
251+
let result = SmallVec::<[_; 8]>::new();
252+
for item in mem::replace(&mut items, cx.tcx.arena.alloc_slice(&result)).iter() {
252253
if item.ident.name.as_str() == *segment {
253254
if path_it.peek().is_none() {
254255
return Some(item.res);

tests/ui/for_loop.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,83 +66,83 @@ error: it is more concise to loop over references to containers instead of using
6666
--> $DIR/for_loop.rs:107:15
6767
|
6868
LL | for _v in vec.iter() {}
69-
| ^^^^^^^^^^
69+
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
7070
|
7171
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
7272

7373
error: it is more concise to loop over references to containers instead of using explicit iteration methods
7474
--> $DIR/for_loop.rs:109:15
7575
|
7676
LL | for _v in vec.iter_mut() {}
77-
| ^^^^^^^^^^^^^^
77+
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
7878

7979
error: it is more concise to loop over containers instead of using explicit iteration methods`
8080
--> $DIR/for_loop.rs:112:15
8181
|
8282
LL | for _v in out_vec.into_iter() {}
83-
| ^^^^^^^^^^^^^^^^^^^
83+
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
8484
|
8585
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
8686

8787
error: it is more concise to loop over references to containers instead of using explicit iteration methods
8888
--> $DIR/for_loop.rs:115:15
8989
|
9090
LL | for _v in array.into_iter() {}
91-
| ^^^^^^^^^^^^^^^^^
91+
| ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`
9292

9393
error: it is more concise to loop over references to containers instead of using explicit iteration methods
9494
--> $DIR/for_loop.rs:120:15
9595
|
9696
LL | for _v in [1, 2, 3].iter() {}
97-
| ^^^^^^^^^^^^^^^^
97+
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
9898

9999
error: it is more concise to loop over references to containers instead of using explicit iteration methods
100100
--> $DIR/for_loop.rs:124:15
101101
|
102102
LL | for _v in [0; 32].iter() {}
103-
| ^^^^^^^^^^^^^^
103+
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
104104

105105
error: it is more concise to loop over references to containers instead of using explicit iteration methods
106106
--> $DIR/for_loop.rs:129:15
107107
|
108108
LL | for _v in ll.iter() {}
109-
| ^^^^^^^^^
109+
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
110110

111111
error: it is more concise to loop over references to containers instead of using explicit iteration methods
112112
--> $DIR/for_loop.rs:132:15
113113
|
114114
LL | for _v in vd.iter() {}
115-
| ^^^^^^^^^
115+
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
116116

117117
error: it is more concise to loop over references to containers instead of using explicit iteration methods
118118
--> $DIR/for_loop.rs:135:15
119119
|
120120
LL | for _v in bh.iter() {}
121-
| ^^^^^^^^^
121+
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
122122

123123
error: it is more concise to loop over references to containers instead of using explicit iteration methods
124124
--> $DIR/for_loop.rs:138:15
125125
|
126126
LL | for _v in hm.iter() {}
127-
| ^^^^^^^^^
127+
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
128128

129129
error: it is more concise to loop over references to containers instead of using explicit iteration methods
130130
--> $DIR/for_loop.rs:141:15
131131
|
132132
LL | for _v in bt.iter() {}
133-
| ^^^^^^^^^
133+
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
134134

135135
error: it is more concise to loop over references to containers instead of using explicit iteration methods
136136
--> $DIR/for_loop.rs:144:15
137137
|
138138
LL | for _v in hs.iter() {}
139-
| ^^^^^^^^^
139+
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
140140

141141
error: it is more concise to loop over references to containers instead of using explicit iteration methods
142142
--> $DIR/for_loop.rs:147:15
143143
|
144144
LL | for _v in bs.iter() {}
145-
| ^^^^^^^^^
145+
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
146146

147147
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
148148
--> $DIR/for_loop.rs:149:15

0 commit comments

Comments
 (0)