rust-lang / rust-lang/rust-clippy

Clippy should detect opportunities for `into_` variants

Open
#8,130 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

Identify places where an into_* function variant might be more efficient than cases where a non-into plus a clone is being used.

Lint Name

use_into_version

Category

style, perf

Advantage
  • Removes unnecessary allocations of types by moving them
  • Cleans up code
Drawbacks

No response

Example
// Note: this function receives and returns owned values
fn get_keys(hm: HashMap<String, u32>) -> Vec<String> {
    hm.keys().map(|k| k.to_string()).collect()
}

Could be written as:

fn get_keys(hm: HashMap<String, u32>) -> Vec<String> {
    hm.into_keys().collect()
}

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

Start by reviewing how Clippy lints are structured and how the proposed use_into_version pattern could be detected. Use the HashMap<String, u32> example as the initial case, then determine the intended broader scope. Done means the lint identifies eligible non-into calls followed by cloning and avoids inappropriate suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.