rust-lang / rust-lang/rust-clippy

`unused_io_amount` doesn't fire when UFCS is used

Open
#9,226 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the unused_io_amount lint implementation and its existing method-call handling, then run the provided Rust reproducer for UFCS Read::read and Write::write. Done means the lint reports the same unhandled I/O amounts for UFCS calls as it does for method calls, with coverage for both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.