rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`unused_io_amount` doesn't fire when UFCS is used

Open Kixunil opened this issue 2 years ago • 1 comments

Summary

When UFCS is used - std::io::Read::read() or std::io::Write::write() instead of a method call the lint doesn't fire even though it should for exactly the same reasons it fires for method call.

Lint Name

unused_io_amount

Reproducer

I tried this code:

fn main() {
    let mut reader = std::fs::File::open("foo").unwrap();
    let mut buf = [0u8; 42];
    std::io::Read::read(&mut reader, &mut buf).unwrap();
    println!("{:?}", buf);
}

write version

I expected to see this happen:

error: read amount is not handled
 --> src/main.rs:4:5
  |
4 |     std::io::Read::read(&mut reader, &mut buf).unwrap();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[deny(clippy::unused_io_amount)]` on by default
  = help: use `Read::read_exact` instead, or handle partial reads
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount

Analogically for write.

Instead, this happened:

No error, no warning, no output.

Version

From playground: 0.1.64 (2022-07-21 62b272d)
(sorry, don't have full output)

Kixunil avatar Jul 22 '22 07:07 Kixunil

This is true for a lot of lints on methods, not just unused_io_amount.

Jarcho avatar Jul 22 '22 14:07 Jarcho