summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/write_literal_2.rs
blob: aa0c13c134080aa7e18f3d2abbd5226ef27c7054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//@no-rustfix: overlapping suggestions
#![allow(unused_must_use)]
#![warn(clippy::needless_raw_strings, clippy::write_literal)]

use std::io::Write;

fn main() {
    let mut v = Vec::new();

    writeln!(v, "{}", "{hello}");
    //~^ ERROR: literal with an empty format string
    //~| NOTE: `-D clippy::write-literal` implied by `-D warnings`
    writeln!(v, r"{}", r"{hello}");
    //~^ ERROR: unnecessary raw string literal
    //~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings`
    //~| ERROR: literal with an empty format string
    writeln!(v, "{}", '\'');
    //~^ ERROR: literal with an empty format string
    writeln!(v, "{}", '"');
    //~^ ERROR: literal with an empty format string
    writeln!(v, r"{}", '"');
    //~^ ERROR: literal with an empty format string
    writeln!(v, r"{}", '\'');
    //~^ ERROR: literal with an empty format string
    writeln!(
        v,
        "some {}",
        "hello \
        //~^ ERROR: literal with an empty format string
        world!"
    );
    writeln!(
        v,
        "some {}\
        {} \\ {}",
        "1",
        "2",
        "3",
        //~^ ERROR: literal with an empty format string
    );
    writeln!(v, "{}", "\\");
    //~^ ERROR: literal with an empty format string
    writeln!(v, r"{}", "\\");
    //~^ ERROR: literal with an empty format string
    writeln!(v, r#"{}"#, "\\");
    //~^ ERROR: literal with an empty format string
    writeln!(v, "{}", r"\");
    //~^ ERROR: literal with an empty format string
    writeln!(v, "{}", "\r");
    //~^ ERROR: literal with an empty format string
    // hard mode
    writeln!(v, r#"{}{}"#, '#', '"');
    //~^ ERROR: literal with an empty format string
    //~| ERROR: literal with an empty format string
    // should not lint
    writeln!(v, r"{}", "\r");
}