Skip to content

New lint: clippy::no_write_and_append #9628

@SkyfallWasTaken

Description

@SkyfallWasTaken

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions