Summary
In case of tuple elements are asymmetric, eg. (src, dst), simply tuple.into() erase all binding names and make it seem like all elements are interchangeable, also hiding the asymmetry.
let [src, dest]: [_; 2] = args.try_into().ok()?;
operations.push((src, dest)); // <- warning
Suggested code is not obvious what each element means. It seems like to be an iterator which is general over array length, but is actually not.
operations.push(<[_; 2]>::try_from(args).ok()?.into());
Lint Name
tuple_array_conversions
Reproducer
I tried this code:
use std::path::PathBuf;
pub fn parse_ops_from_args_warn(args: Vec<PathBuf>, operations: &mut Vec<(PathBuf, PathBuf)>) -> Option<()> {
let [src, dest]: [_; 2] = args.try_into().ok()?;
operations.push((src, dest)); // <- warning
Some(())
}
pub fn parse_ops_from_args_suggested(args: Vec<PathBuf>, operations: &mut Vec<(PathBuf, PathBuf)>) -> Option<()> {
operations.push(<[_; 2]>::try_from(args).ok()?.into());
Some(())
}
I saw this happen:
warning: it looks like you're trying to convert an array to a tuple
--> src/lib.rs:5:21
|
5 | operations.push((src, dest));
| ^^^^^^^^^^^
|
= help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions
= note: `#[warn(clippy::tuple_array_conversions)]` on by default
I expected to see this happen: no warnings.
Version
Clippy 0.1.72 (2023-07-02 839e9a6)
On Rust playground nightly.
Additional Labels
No response
Summary
In case of tuple elements are asymmetric, eg.
(src, dst), simplytuple.into()erase all binding names and make it seem like all elements are interchangeable, also hiding the asymmetry.Suggested code is not obvious what each element means. It seems like to be an iterator which is general over array length, but is actually not.
Lint Name
tuple_array_conversions
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen: no warnings.
Version
Additional Labels
No response