Skip to content

false negative write_with_newline: format string that starts with \n #8741

Closed
@matthiaskrgr

Description

@matthiaskrgr

Summary

If a format string starts with a \n, the lint does not seem to fire.
I had a quick glance at the lint code but I didn't see anything that would indicate that this is intentional.

Lint Name

clippy::write_with_newline

Reproducer

I tried this code:

use std::fmt::Write as _;

pub fn main() {
    let mut s = String::new();
    let x = "a";
    write!(s, "\n{}\n", x).unwrap(); // should warn
    dbg!(s);
}

would expect a warning here since we can write writeln!(s, "\n{}")

Version

clippy 0.1.62 (7b8a08cf1 2022-04-21)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions