Skip to content

Commit f5376a3

Browse files
authored
Merge pull request #3119 from joshtriplett/a-message-from-the-save-the-iters-foundation
iter conservation efforts: save the endangered .iter() and .into_iter()
2 parents 2b7a530 + 7799883 commit f5376a3

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

clippy_lints/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
449449
if_not_else::IF_NOT_ELSE,
450450
infinite_iter::MAYBE_INFINITE_ITER,
451451
items_after_statements::ITEMS_AFTER_STATEMENTS,
452+
loops::EXPLICIT_INTO_ITER_LOOP,
453+
loops::EXPLICIT_ITER_LOOP,
452454
matches::SINGLE_MATCH_ELSE,
453455
methods::FILTER_MAP,
454456
methods::OPTION_MAP_UNWRAP_OR,
@@ -546,8 +548,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
546548
literal_representation::UNREADABLE_LITERAL,
547549
loops::EMPTY_LOOP,
548550
loops::EXPLICIT_COUNTER_LOOP,
549-
loops::EXPLICIT_INTO_ITER_LOOP,
550-
loops::EXPLICIT_ITER_LOOP,
551551
loops::FOR_KV_MAP,
552552
loops::FOR_LOOP_OVER_OPTION,
553553
loops::FOR_LOOP_OVER_RESULT,
@@ -718,8 +718,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
718718
literal_representation::LARGE_DIGIT_GROUPS,
719719
literal_representation::UNREADABLE_LITERAL,
720720
loops::EMPTY_LOOP,
721-
loops::EXPLICIT_INTO_ITER_LOOP,
722-
loops::EXPLICIT_ITER_LOOP,
723721
loops::FOR_KV_MAP,
724722
loops::NEEDLESS_RANGE_LOOP,
725723
loops::WHILE_LET_ON_ITERATOR,

clippy_lints/src/loops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ declare_clippy_lint! {
8585
/// ```
8686
declare_clippy_lint! {
8787
pub EXPLICIT_ITER_LOOP,
88-
style,
88+
pedantic,
8989
"for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do"
9090
}
9191

@@ -107,7 +107,7 @@ declare_clippy_lint! {
107107
/// ```
108108
declare_clippy_lint! {
109109
pub EXPLICIT_INTO_ITER_LOOP,
110-
style,
110+
pedantic,
111111
"for-looping over `_.into_iter()` when `_` would do"
112112
}
113113

@@ -1209,7 +1209,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_
12091209
cx,
12101210
EXPLICIT_ITER_LOOP,
12111211
arg.span,
1212-
"it is more idiomatic to loop over references to containers instead of using explicit \
1212+
"it is more concise to loop over references to containers instead of using explicit \
12131213
iteration methods",
12141214
"to write this more concisely, try",
12151215
format!("&{}{}", muta, object),
@@ -1247,7 +1247,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
12471247
cx,
12481248
EXPLICIT_INTO_ITER_LOOP,
12491249
arg.span,
1250-
"it is more idiomatic to loop over containers instead of using explicit \
1250+
"it is more concise to loop over containers instead of using explicit \
12511251
iteration methods`",
12521252
"to write this more concisely, try",
12531253
object.to_string(),

tests/ui/for_loop.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,83 +264,83 @@ error: this range is empty so this for loop will never run
264264
193 | for i in (5 + 2)..(8 - 1) {
265265
| ^^^^^^^^^^^^^^^^
266266

267-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
267+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
268268
--> $DIR/for_loop.rs:215:15
269269
|
270270
215 | for _v in vec.iter() {}
271271
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
272272
|
273273
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
274274

275-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
275+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
276276
--> $DIR/for_loop.rs:217:15
277277
|
278278
217 | for _v in vec.iter_mut() {}
279279
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
280280

281-
error: it is more idiomatic to loop over containers instead of using explicit iteration methods`
281+
error: it is more concise to loop over containers instead of using explicit iteration methods`
282282
--> $DIR/for_loop.rs:220:15
283283
|
284284
220 | for _v in out_vec.into_iter() {}
285285
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
286286
|
287287
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
288288

289-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
289+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
290290
--> $DIR/for_loop.rs:223:15
291291
|
292292
223 | for _v in array.into_iter() {}
293293
| ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`
294294

295-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
295+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
296296
--> $DIR/for_loop.rs:228:15
297297
|
298298
228 | for _v in [1, 2, 3].iter() {}
299299
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
300300

301-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
301+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
302302
--> $DIR/for_loop.rs:232:15
303303
|
304304
232 | for _v in [0; 32].iter() {}
305305
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
306306

307-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
307+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
308308
--> $DIR/for_loop.rs:237:15
309309
|
310310
237 | for _v in ll.iter() {}
311311
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
312312

313-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
313+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
314314
--> $DIR/for_loop.rs:240:15
315315
|
316316
240 | for _v in vd.iter() {}
317317
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
318318

319-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
319+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
320320
--> $DIR/for_loop.rs:243:15
321321
|
322322
243 | for _v in bh.iter() {}
323323
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
324324

325-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
325+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
326326
--> $DIR/for_loop.rs:246:15
327327
|
328328
246 | for _v in hm.iter() {}
329329
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
330330

331-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
331+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
332332
--> $DIR/for_loop.rs:249:15
333333
|
334334
249 | for _v in bt.iter() {}
335335
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
336336

337-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
337+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
338338
--> $DIR/for_loop.rs:252:15
339339
|
340340
252 | for _v in hs.iter() {}
341341
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
342342

343-
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
343+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
344344
--> $DIR/for_loop.rs:255:15
345345
|
346346
255 | for _v in bs.iter() {}

0 commit comments

Comments
 (0)