Skip to content

.read().ok() does not trigger unused_io_amount warning #7096

Closed
@VictorKoenders

Description

@VictorKoenders

Lint name: unused_io_amount

I tried this code:

fn test(file: &str) -> Option<()> {
    let mut reader = std::fs::File::open(file).ok()?;
    let mut result = [0u8; 0];
    // reader.read(&mut result).unwrap(); // clippy correctly warns about this
    reader.read(&mut result).ok()?; // clippy does not warn about this
    Some(())
}
<code>

I expected to see this happen: explanation

If you use reader.read(&mut result).unwrap(), clippy correctly triggers error "read amount is not handled. Use Read::read_exact instead"

Instead, this happened: explanation

Appending .ok()? consumes the error, but clippy does not report the unused_io_amount warning any more.

Meta

  • cargo clippy -V: clippy 0.1.51 (2fd73fa 2021-03-23)
  • rustc -Vv:
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.0.1

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions