rust-lang / rust-lang/rust-clippy

lint needless borrows in format args

Open
#7,961 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

This could probably be its own lint rather than an extension of needless_borrow (on the user facing side at least, so that we can allow/deny that specific part of the lint)

When passing args to format!() and and friends, we actually don't need to explicitly use a &borrow because we don't consume the object:

    println!("{:?} {} {}", &a, &b, &c.display());

could as well be:

    println!("{:?} {} {}", a, b, c.display());

as this code sample demonstrates:

pub fn main() {
    let a = vec!['a'];
    let b = "hello";
    let c = std::path::PathBuf::from("/");

    println!("{:?} {} {}", a, b, c.display());

    std::mem::drop(a);
    std::mem::drop(b);
    std::mem::drop(c);
}

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 reading the existing needless_borrow lint and the format-argument examples in this issue. Determine how a separate user-facing lint should recognize unnecessary borrows in format! and related macros; done means the lint can be independently allowed or denied and covers the demonstrated cases.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.