rust-lang / rust-lang/rust-clippy
New Lint Request: BufWriter must be flushed before being dropped
Open
@lukaslueg is already working on this.
Since Apr 22, 2023.
A-lint
E-medium
L-correctness
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
fn run() -> io::Result<()> {
let mut buf = BufWriter::new(File::open("src/main.rs")?);
writeln!(buf, "foo")?;
Ok(())
}
should be
fn run() -> io::Result<()> {
let mut buf = BufWriter::new(File::open("src/main.rs")?);
writeln!(buf, "foo")?;
buf.flush()?;
Ok(())
}
File::open returns read-only File instance, so these fns should return Err.
But the former fn silently returns Ok because BufWriter::drop ignores flush errors.
https://play.rust-lang.org/?gist=1efc55d8a54d5b9eea25132d085c478c&version=stable
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.
Assessment
This issue has not been assessed yet.