rust-lang / rust-lang/rust-clippy

Lint that replaces a destructive assignment of one field from a tuple with an index-based value

Open
#7,530 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

This Lint recommends avoiding destructuring a tuple if only one of its values is used and the rest are wildcard patterns(_) and, instead, recommends getting the value directly by index.

Categories (optional)
  • Kind: clippy::style

What is the advantage of the recommended code over the original code

It's shorter and easier to read.
The difference is especially noticeable in tuples of size 4 and larger.

Drawbacks

There shouldn't be, but I can be wrong.

Example
let (variableName, _)     = ("One", "Two");
let (_, variableName2, _) = ("One", "Two", "Three");

Could be written as:

let variableName  = ("One", "Two").0;
let variableName2 = ("One", "Two", "Three").1;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files, tests, or entry points. Start by locating the existing Clippy lint implementations and their tests, then add the tuple-destructuring-to-index recommendation and tests covering the shown examples; done means the lint detects those patterns and produces the proposed indexed form.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.