Skip to content

tuple_array_conversion false positive on destructured tuple values #11144

Closed
@MingweiSamuel

Description

@MingweiSamuel

Summary

The tuple_array_conversion seems to be way to zealous in detecting the original tuple identifiers, generating false positives even when the names are assigned through destructuring. These all trigger it even though it makes no sense to:

let (a, (_b, c)) = get_tuple_a();
let _ = [a, c];

let (a, [_b, c]) = get_tuple_b();
let _ = [a, c];

let (a, Wrap(b)) = get_tuple_c();
let _ = [a, b];

full code below

Lint Name

tuple_array_conversion

Reproducer

full code:

fn get_tuple_a() -> (usize, (usize, usize)) {
    (1, (2, 3))
}

fn get_tuple_b() -> (usize, [usize; 2]) {
    (1, [2, 3])
}

struct Wrap<T>(pub T);
fn get_tuple_c() -> (usize, Wrap<usize>) {
    (1, Wrap(2))
}

fn main() {
    let (a, (_b, c)) = get_tuple_a();
    let _ = [a, c];

    let (a, [_b, c]) = get_tuple_b();
    let _ = [a, c];
    
    let (a, Wrap(b)) = get_tuple_c();
    let _ = [a, b];
}
    Checking playground v0.0.1 (/playground)
warning: it looks like you're trying to convert a tuple to an array
  --> src/main.rs:16:13
   |
16 |     let _ = [a, c];
   |             ^^^^^^
   |
   = help: use `.into()` instead, or `<[T; N]>::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

warning: it looks like you're trying to convert a tuple to an array
  --> src/main.rs:19:13
   |
19 |     let _ = [a, c];
   |             ^^^^^^
   |
   = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions

warning: it looks like you're trying to convert a tuple to an array
  --> src/main.rs:22:13
   |
22 |     let _ = [a, b];
   |             ^^^^^^
   |
   = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions

warning: `playground` (bin "playground") generated 3 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 0.44s

playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=504c4f33d4880029600437ce2a068acf

Version

1.73.0-nightly
(2023-07-11 993deaa0bf8bab9dd3ea)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions