Skip to content

#[warn(unused_mut)] does not always warn #25049

Closed
@nwin

Description

@nwin

rustc fails to warn about unused mut for buf in this case:

use std::io;

pub fn read_all<R: io::Read + ?Sized>(this: &mut R, mut buf: &mut [u8]) -> io::Result<()> {
    let mut total = 0;
    while total < buf.len() {
        match this.read(&mut buf[total..]) {
            Ok(0) => return Err(io::Error::new(io::ErrorKind::Other,
                                               "failed to read whole buffer")),
            Ok(n) => total += n,
            Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
            Err(e) => return Err(e),
        }
    }
    Ok(())
}

fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions