rust-lang / rust-lang/rust-clippy

feature request: passing File::open value to where Write is expected

Open
#8,608 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

detects passing File::open value to place where Write is expected

Lint Name

file_is_not_writable

Category

suspicious

Advantage
  • Remove "bad file descriptor" errors at runtime.
Drawbacks

none

Example
let file = File::open("config.txt"); // this handle is read-only
let buf_write = BufWriter::new(file);

Could be written as below when above 1.58.0:

let file = File::options().write(true).open("config.txt");
let buf_write = BufWriter::new(file);

when below 1.58.0:

let file = OpenOptions::new().write(true).open("config.txt");
let buf_write = BufWriter::new(file);

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 existing Clippy lint entry point for file_is_not_writable and review how suspicious lints inspect Rust expressions and types. Use the File::open and BufWriter examples as the behavior to cover, and consider the shown File::options and OpenOptions forms acceptable alternatives. Done means the lint detects the read-only handle passed where Write is expected without flagging writable opens.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.