Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tuple_array_conversions lint on nightly #11379

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/tuple_array_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/tuple_array_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const N: usize>() {
let src = [0; N];
let dest: (u8,) = (src[0],);
}
}

#[clippy::msrv = "1.70.0"]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/tuple_array_conversions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ 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]);
| ^^^^^^^^^^^^
|
= 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];
| ^^^^^^^^^^
Expand Down