From e35eb91a337431b5894aa6755d0d8317b9aa2cca Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 22 Aug 2023 13:15:05 +0400 Subject: [PATCH 1/2] Fix tuple_array_conversions lint on nightly --- clippy_lints/src/tuple_array_conversions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 78ad52d8a8794..c12519d723c08 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -189,8 +189,8 @@ fn all_bindings_are_for_conv<'tcx>( tys.len() == elements.len() && tys.iter().chain(final_tys.iter().copied()).all_equal() }, (ToType::Tuple, ty::Array(ty, len)) => { - len.eval_target_usize(cx.tcx, cx.param_env) as usize == elements.len() - && final_tys.iter().chain(once(ty)).all_equal() + let Some(len) = len.try_eval_target_usize(cx.tcx, cx.param_env) else { return false }; + len as usize == elements.len() && final_tys.iter().chain(once(ty)).all_equal() }, _ => false, } From f0eaa662632c8e85b07063507930dc77fdd3e1e3 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 23 Aug 2023 09:54:50 +0400 Subject: [PATCH 2/2] Add a test for tuple_array_conversion --- tests/ui/tuple_array_conversions.rs | 5 +++++ tests/ui/tuple_array_conversions.stderr | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index ed21ee668e3a0..ca79cc104f223 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -82,6 +82,11 @@ fn main() { [a, c]; let [[a, b], [c, d]] = [[1, 2], [3, 4]]; (a, c); + // Array length is not usize (#11144) + fn generic_array_length() { + let src = [0; N]; + let dest: (u8,) = (src[0],); + } } #[clippy::msrv = "1.70.0"] diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index 50bdcf29d1fad..70c13d10fd875 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -64,7 +64,7 @@ LL | (src, dest); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> $DIR/tuple_array_conversions.rs:99:13 + --> $DIR/tuple_array_conversions.rs:104:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let x = (x[0], x[1]); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> $DIR/tuple_array_conversions.rs:100:13 + --> $DIR/tuple_array_conversions.rs:105:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^