Skip to content

Identify when buffer is being reused in read_line without clearing #3534

Open
@estebank

Description

@estebank

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 rust-lang/rust#56681 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-MIRType: This lint will require working with the MIR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions