You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#![allow(unused_variables)]
fn main() {
let t1: &[(u32, u32)] = &[(1, 2), (3, 4)];
let v2: Vec<[u32; 2]> = t1.iter().map(|&t| t.into()).collect();
let t3: Vec<(u32, u32)> = v2.iter().map(|&v| v.into()).collect();
}
The lint should work with longer arrays/tuples too. There are many more complex situations where the .into() could be used to convert between arrays and tuples, but I think this basic case is enough to keep lint logic simple, and it's enough to teach the programmer this transformation is allowed (Clippy is also a teaching tool).
The text was updated successfully, but these errors were encountered:
New lint [`tuple_array_conversions`]
Closes#10748
PS, the implementation is a bit ugly 😅 ~~I will likely refactor soon enough :)~~ Done :D
changelog: New lint [`tuple_array_conversions`]
What it does
It suggests better code in cases of conversions from/to tuples to/from arrays.
Lint Name
simple_tuple_array_conversion
Category
style
Advantage
The code is simpler, shorter, less bug-prone.
Since this the array <=> tuple conversions are allowed:
rust-lang/rust#97594
Drawbacks
None.
Example
Could be written as:
The lint should work with longer arrays/tuples too. There are many more complex situations where the .into() could be used to convert between arrays and tuples, but I think this basic case is enough to keep lint logic simple, and it's enough to teach the programmer this transformation is allowed (Clippy is also a teaching tool).
The text was updated successfully, but these errors were encountered: