rust-lang / rust-lang/rust-clippy
`unused_io_amount` fails to fire on offending code
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Code on playground:
Code was found in a bigger codebase where the same lint previously fired on some other patterns. The example is obviously incorrect as it does not care about how many bytes were written in any of the write calls. Considering how close this code is to the documented example, I'm not entirely sure whether it's an actual bug or a PEBKAC.
Lint Name
unused_io_amount
Reproducer
I tried this code:
use std::io::Write;
const END: u8 = 0xC0;
const ESC: u8 = 0xDB;
const ESC_END: u8 = 0xDC;
const ESC_ESC: u8 = 0xDD;
pub fn encode_byte(writer: &mut impl Write, byte: u8) -> std::io::Result<()> {
match byte {
END => writer.write(&[ESC, ESC_END])?,
ESC => writer.write(&[ESC, ESC_ESC])?,
byte => writer.write(&[byte])?,
};
Ok(())
}
I expected to see this happen:
Clippy should have reported errors.
Instead, this happened:
Nothing.
Version
rustc 1.61.0-nightly (335ffbfa5 2022-03-11)
binary: rustc
commit-hash: 335ffbfa547df94ac236f5c56130cecf99c8d82b
commit-date: 2022-03-11
host: x86_64-pc-windows-msvc
release: 1.61.0-nightly
LLVM version: 14.0.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the unused_io_amount lint entry point and run the supplied playground reproducer with the listed Rust version. Compare its behavior with the documented example and verify whether the three write calls should produce lint errors; done means the reported behavior is explained and covered by an appropriate regression test.
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
- Mostly clear
- Newbie friendliness
- 45/100