Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New lint: clippy::no_write_and_append #9628

Closed
SkyfallWasTaken opened this issue Oct 10, 2022 · 0 comments · Fixed by #11902
Closed

New lint: clippy::no_write_and_append #9628

SkyfallWasTaken opened this issue Oct 10, 2022 · 0 comments · Fixed by #11902
Labels
A-lint Area: New lints

Comments

@SkyfallWasTaken
Copy link

What it does

This lint would warn when a user uses std::fs::OpenOptions or tokio::fs::OpenOptions and calls both write and append

Lint Name

no_write_and_append

Category

correctness, suspicious, pedantic

Advantage

  • Remove write call that doesn't have any affect

Drawbacks

Some people might do this deliberately to highlight that writes are enabled.

Example

use std::fs::OpenOptions;

fn main() {
    let file = OpenOptions::new()
        .create(true)
		.write(true) // useless `write` call, `append` will make it writable anyway
        .append(true)
        .open("dump.json")
        .unwrap();
}

Could be written as:

use std::fs::OpenOptions;

fn main() {
    let file = OpenOptions::new()
        .create(true)
        .append(true)
        .open("dump.json")
        .unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant