Skip to content

Commit 9af07e6

Browse files
committed
Auto merge of rust-lang#7138 - mgacek8:issue6808_iter_cloned_collect_FN_with_large_array, r=Manishearth
Fix FN in `iter_cloned_collect` with a large array fixes rust-lang#6808 changelog: Fix FN in `iter_cloned_collect` with a large array I spotted that [is_iterable_array](https://github.com/rust-lang/rust-clippy/blob/a362a4d1d0edb66aef186c1d27b28c60573078f4/clippy_lints/src/loops/explicit_iter_loop.rs#L67-L75) function that `explicit_iter_loop` lint is using only works for array sizes <= 32. There is this comment: > IntoIterator is currently only implemented for array sizes <= 32 in rustc I'm a bit confused, because I read that [IntoIterator for arrays](https://doc.rust-lang.org/src/core/array/mod.rs.html#194-201) with const generic `N` is stable since = "1.0.0". Although Const Generics MVP were stabilized in Rust 1.51. Should I set MSRV for the current change? I will try to test with older compilers soon.
2 parents 0a330e6 + d7627dc commit 9af07e6

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

clippy_lints/src/methods/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ pub(super) fn derefs_to_slice<'tcx>(
1818
ty::Slice(_) => true,
1919
ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
2020
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::vec_type),
21-
ty::Array(_, size) => size
22-
.try_eval_usize(cx.tcx, cx.param_env)
23-
.map_or(false, |size| size < 32),
21+
ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(),
2422
ty::Ref(_, inner, _) => may_slice(cx, inner),
2523
_ => false,
2624
}

tests/ui/iter_cloned_collect.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ fn main() {
1919
let _: Vec<u8> = std::ffi::CStr::from_ptr(std::ptr::null())
2020
.to_bytes().to_vec();
2121
}
22+
23+
// Issue #6808
24+
let arr: [u8; 64] = [0; 64];
25+
let _: Vec<_> = arr.to_vec();
2226
}

tests/ui/iter_cloned_collect.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ fn main() {
2222
.cloned()
2323
.collect();
2424
}
25+
26+
// Issue #6808
27+
let arr: [u8; 64] = [0; 64];
28+
let _: Vec<_> = arr.iter().cloned().collect();
2529
}

tests/ui/iter_cloned_collect.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ LL | | .cloned()
2222
LL | | .collect();
2323
| |______________________^ help: try: `.to_vec()`
2424

25-
error: aborting due to 3 previous errors
25+
error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable
26+
--> $DIR/iter_cloned_collect.rs:28:24
27+
|
28+
LL | let _: Vec<_> = arr.iter().cloned().collect();
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()`
30+
31+
error: aborting due to 4 previous errors
2632

0 commit comments

Comments
 (0)