Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VictorKoenders opened this issue Apr 16, 2021 · 1 comment · Fixed by #7100
Closed

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

VictorKoenders opened this issue Apr 16, 2021 · 1 comment · Fixed by #7100
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@VictorKoenders
Copy link

VictorKoenders commented Apr 16, 2021

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
@VictorKoenders VictorKoenders added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Apr 16, 2021
@ABouttefeux
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants