rust-lang / rust-lang/rust-clippy

Identify when buffer is being reused in `read_line` without clearing

Open
#3,534 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Identify when a buffer is being reused without clearing in at least read_line, ideally in a general manner (might be impossible to do so), like in the following case:

use std::io;

fn main() {
    let mut guess = String::new();

    loop {
        println!("Enter a number");

        io::stdin().read_line(&mut guess).unwrap();

        println!("guess: {}", guess);
        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(err) => {
                println!("{:?}", err);
                continue
            },
        };
}

CC https://github.com/rust-lang/rust/issues/56681#issuecomment-446431862

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 with the provided read_line example and investigate how Clippy could detect a reused buffer that is not cleared. Determine whether a general lint is feasible beyond this case, then define the diagnostic behavior and verify it with focused examples and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.