Skip to content

Commit 954eb83

Browse files
committed
Deprecate into_iter_on_array lint
This lint was uplifted/reimplemented by rustc. Rustup to rust-lang/rust#66017
1 parent e917b01 commit 954eb83

14 files changed

+67
-127
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 331 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/deprecated_lints.rs

+9
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@ declare_deprecated_lint! {
130130
pub UNUSED_COLLECT,
131131
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint"
132132
}
133+
134+
/// **What it does:** Nothing. This lint has been deprecated.
135+
///
136+
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
137+
/// `array_into_iter`.
138+
declare_deprecated_lint! {
139+
pub INTO_ITER_ON_ARRAY,
140+
"this lint has been uplifted to rustc and is now called `array_into_iter`"
141+
}

clippy_lints/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
430430
"clippy::unused_collect",
431431
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint",
432432
);
433+
store.register_removed(
434+
"clippy::into_iter_on_array",
435+
"this lint has been uplifted to rustc and is now called `array_into_iter`",
436+
);
433437
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
434438

435439
// begin register lints, do not remove this comment, it’s used in `update_lints`
@@ -584,7 +588,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
584588
&methods::FLAT_MAP_IDENTITY,
585589
&methods::GET_UNWRAP,
586590
&methods::INEFFICIENT_TO_STRING,
587-
&methods::INTO_ITER_ON_ARRAY,
588591
&methods::INTO_ITER_ON_REF,
589592
&methods::ITER_CLONED_COLLECT,
590593
&methods::ITER_NTH,
@@ -1142,7 +1145,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
11421145
LintId::of(&methods::FILTER_NEXT),
11431146
LintId::of(&methods::FLAT_MAP_IDENTITY),
11441147
LintId::of(&methods::INEFFICIENT_TO_STRING),
1145-
LintId::of(&methods::INTO_ITER_ON_ARRAY),
11461148
LintId::of(&methods::INTO_ITER_ON_REF),
11471149
LintId::of(&methods::ITER_CLONED_COLLECT),
11481150
LintId::of(&methods::ITER_NTH),
@@ -1481,7 +1483,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
14811483
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
14821484
LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
14831485
LintId::of(&methods::CLONE_DOUBLE_REF),
1484-
LintId::of(&methods::INTO_ITER_ON_ARRAY),
14851486
LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
14861487
LintId::of(&methods::UNINIT_ASSUMED_INIT),
14871488
LintId::of(&minmax::MIN_MAX),

clippy_lints/src/methods/mod.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -968,34 +968,6 @@ declare_clippy_lint! {
968968
"using `filter_map` when a more succinct alternative exists"
969969
}
970970

971-
declare_clippy_lint! {
972-
/// **What it does:** Checks for `into_iter` calls on types which should be replaced by `iter` or
973-
/// `iter_mut`.
974-
///
975-
/// **Why is this bad?** Arrays and `PathBuf` do not yet have an `into_iter` method which move out
976-
/// their content into an iterator. Auto-referencing resolves the `into_iter` call to its reference
977-
/// instead, like `<&[T; N] as IntoIterator>::into_iter`, which just iterates over item references
978-
/// like calling `iter` would. Furthermore, when the standard library actually
979-
/// [implements the `into_iter` method](https://github.com/rust-lang/rust/issues/25725) which moves
980-
/// the content out of the array, the original use of `into_iter` got inferred with the wrong type
981-
/// and the code will be broken.
982-
///
983-
/// **Known problems:** None
984-
///
985-
/// **Example:**
986-
///
987-
/// ```rust
988-
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
989-
/// ```
990-
/// Could be written as:
991-
/// ```rust
992-
/// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
993-
/// ```
994-
pub INTO_ITER_ON_ARRAY,
995-
correctness,
996-
"using `.into_iter()` on an array"
997-
}
998-
999971
declare_clippy_lint! {
1000972
/// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter`
1001973
/// or `iter_mut`.
@@ -1133,7 +1105,6 @@ declare_lint_pass!(Methods => [
11331105
USELESS_ASREF,
11341106
UNNECESSARY_FOLD,
11351107
UNNECESSARY_FILTER_MAP,
1136-
INTO_ITER_ON_ARRAY,
11371108
INTO_ITER_ON_REF,
11381109
SUSPICIOUS_MAP,
11391110
UNINIT_ASSUMED_INIT,
@@ -2789,13 +2760,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
27892760
fn ty_has_iter_method(
27902761
cx: &LateContext<'_, '_>,
27912762
self_ref_ty: Ty<'_>,
2792-
) -> Option<(&'static Lint, &'static str, &'static str)> {
2763+
) -> Option<(&'static str, &'static str)> {
27932764
has_iter_method(cx, self_ref_ty).map(|ty_name| {
2794-
let lint = if ty_name == "array" || ty_name == "PathBuf" {
2795-
INTO_ITER_ON_ARRAY
2796-
} else {
2797-
INTO_ITER_ON_REF
2798-
};
27992765
let mutbl = match self_ref_ty.kind {
28002766
ty::Ref(_, _, mutbl) => mutbl,
28012767
_ => unreachable!(),
@@ -2804,18 +2770,18 @@ fn ty_has_iter_method(
28042770
hir::MutImmutable => "iter",
28052771
hir::MutMutable => "iter_mut",
28062772
};
2807-
(lint, ty_name, method_name)
2773+
(ty_name, method_name)
28082774
})
28092775
}
28102776

28112777
fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_>, method_span: Span) {
28122778
if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) {
28132779
return;
28142780
}
2815-
if let Some((lint, kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
2781+
if let Some((kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) {
28162782
span_lint_and_sugg(
28172783
cx,
2818-
lint,
2784+
INTO_ITER_ON_REF,
28192785
method_span,
28202786
&format!(
28212787
"this .into_iter() call is equivalent to .{}() and will not move the {}",

src/lintlist/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 332] = [
9+
pub const ALL_LINTS: [Lint; 331] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -812,13 +812,6 @@ pub const ALL_LINTS: [Lint; 332] = [
812812
deprecation: None,
813813
module: "integer_division",
814814
},
815-
Lint {
816-
name: "into_iter_on_array",
817-
group: "correctness",
818-
desc: "using `.into_iter()` on an array",
819-
deprecation: None,
820-
module: "methods",
821-
},
822815
Lint {
823816
name: "into_iter_on_ref",
824817
group: "style",

tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
#[warn(clippy::misaligned_transmute)]
66
#[warn(clippy::unused_collect)]
77
#[warn(clippy::invalid_ref)]
8+
#[warn(clippy::into_iter_on_array)]
89

910
fn main() {}

tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `i
4242
LL | #[warn(clippy::invalid_ref)]
4343
| ^^^^^^^^^^^^^^^^^^^
4444

45+
error: lint `clippy::into_iter_on_array` has been removed: `this lint has been uplifted to rustc and is now called `array_into_iter``
46+
--> $DIR/deprecated.rs:8:8
47+
|
48+
LL | #[warn(clippy::into_iter_on_array)]
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
4551
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
4652
--> $DIR/deprecated.rs:1:8
4753
|
4854
LL | #[warn(clippy::str_to_string)]
4955
| ^^^^^^^^^^^^^^^^^^^^^
5056

51-
error: aborting due to 8 previous errors
57+
error: aborting due to 9 previous errors
5258

tests/ui/for_loop_fixable.fixed

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Unrelated {
3131
clippy::cognitive_complexity,
3232
clippy::similar_names
3333
)]
34-
#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]
34+
#[allow(clippy::many_single_char_names, unused_variables)]
3535
fn main() {
3636
const MAX_LEN: usize = 42;
3737
let mut vec = vec![1, 2, 3, 4];
@@ -102,9 +102,6 @@ fn main() {
102102
let out_vec = vec![1, 2, 3];
103103
for _v in out_vec {}
104104

105-
let array = [1, 2, 3];
106-
for _v in &array {}
107-
108105
for _v in &vec {} // these are fine
109106
for _v in &mut vec {} // these are fine
110107

tests/ui/for_loop_fixable.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Unrelated {
3131
clippy::cognitive_complexity,
3232
clippy::similar_names
3333
)]
34-
#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]
34+
#[allow(clippy::many_single_char_names, unused_variables)]
3535
fn main() {
3636
const MAX_LEN: usize = 42;
3737
let mut vec = vec![1, 2, 3, 4];
@@ -102,9 +102,6 @@ fn main() {
102102
let out_vec = vec![1, 2, 3];
103103
for _v in out_vec.into_iter() {}
104104

105-
let array = [1, 2, 3];
106-
for _v in array.into_iter() {}
107-
108105
for _v in &vec {} // these are fine
109106
for _v in &mut vec {} // these are fine
110107

tests/ui/for_loop_fixable.stderr

+10-16
Original file line numberDiff line numberDiff line change
@@ -77,64 +77,58 @@ LL | for _v in out_vec.into_iter() {}
7777
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
7878

7979
error: it is more concise to loop over references to containers instead of using explicit iteration methods
80-
--> $DIR/for_loop_fixable.rs:106:15
81-
|
82-
LL | for _v in array.into_iter() {}
83-
| ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`
84-
85-
error: it is more concise to loop over references to containers instead of using explicit iteration methods
86-
--> $DIR/for_loop_fixable.rs:111:15
80+
--> $DIR/for_loop_fixable.rs:108:15
8781
|
8882
LL | for _v in [1, 2, 3].iter() {}
8983
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
9084

9185
error: it is more concise to loop over references to containers instead of using explicit iteration methods
92-
--> $DIR/for_loop_fixable.rs:115:15
86+
--> $DIR/for_loop_fixable.rs:112:15
9387
|
9488
LL | for _v in [0; 32].iter() {}
9589
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
9690

9791
error: it is more concise to loop over references to containers instead of using explicit iteration methods
98-
--> $DIR/for_loop_fixable.rs:120:15
92+
--> $DIR/for_loop_fixable.rs:117:15
9993
|
10094
LL | for _v in ll.iter() {}
10195
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
10296

10397
error: it is more concise to loop over references to containers instead of using explicit iteration methods
104-
--> $DIR/for_loop_fixable.rs:123:15
98+
--> $DIR/for_loop_fixable.rs:120:15
10599
|
106100
LL | for _v in vd.iter() {}
107101
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
108102

109103
error: it is more concise to loop over references to containers instead of using explicit iteration methods
110-
--> $DIR/for_loop_fixable.rs:126:15
104+
--> $DIR/for_loop_fixable.rs:123:15
111105
|
112106
LL | for _v in bh.iter() {}
113107
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
114108

115109
error: it is more concise to loop over references to containers instead of using explicit iteration methods
116-
--> $DIR/for_loop_fixable.rs:129:15
110+
--> $DIR/for_loop_fixable.rs:126:15
117111
|
118112
LL | for _v in hm.iter() {}
119113
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
120114

121115
error: it is more concise to loop over references to containers instead of using explicit iteration methods
122-
--> $DIR/for_loop_fixable.rs:132:15
116+
--> $DIR/for_loop_fixable.rs:129:15
123117
|
124118
LL | for _v in bt.iter() {}
125119
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
126120

127121
error: it is more concise to loop over references to containers instead of using explicit iteration methods
128-
--> $DIR/for_loop_fixable.rs:135:15
122+
--> $DIR/for_loop_fixable.rs:132:15
129123
|
130124
LL | for _v in hs.iter() {}
131125
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
132126

133127
error: it is more concise to loop over references to containers instead of using explicit iteration methods
134-
--> $DIR/for_loop_fixable.rs:138:15
128+
--> $DIR/for_loop_fixable.rs:135:15
135129
|
136130
LL | for _v in bs.iter() {}
137131
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
138132

139-
error: aborting due to 18 previous errors
133+
error: aborting due to 17 previous errors
140134

tests/ui/for_loop_unfixable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
unused,
1818
dead_code
1919
)]
20-
#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]
20+
#[allow(clippy::many_single_char_names, unused_variables)]
2121
fn main() {
2222
for i in 5..5 {
2323
println!("{}", i);

tests/ui/into_iter_on_ref.fixed

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// run-rustfix
22
#![allow(clippy::useless_vec)]
33
#![warn(clippy::into_iter_on_ref)]
4-
#![deny(clippy::into_iter_on_array)]
54

65
struct X;
76
use std::collections::*;
@@ -10,9 +9,7 @@ fn main() {
109
for _ in &[1, 2, 3] {}
1110
for _ in vec![X, X] {}
1211
for _ in &vec![X, X] {}
13-
for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
1412

15-
let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
1613
let _ = vec![1, 2, 3].into_iter();
1714
let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter()
1815
let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter()

tests/ui/into_iter_on_ref.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// run-rustfix
22
#![allow(clippy::useless_vec)]
33
#![warn(clippy::into_iter_on_ref)]
4-
#![deny(clippy::into_iter_on_array)]
54

65
struct X;
76
use std::collections::*;
@@ -10,9 +9,7 @@ fn main() {
109
for _ in &[1, 2, 3] {}
1110
for _ in vec![X, X] {}
1211
for _ in &vec![X, X] {}
13-
for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
1412

15-
let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
1613
let _ = vec![1, 2, 3].into_iter();
1714
let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
1815
let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter()

0 commit comments

Comments
 (0)