about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/single_char_pattern.rs
blob: 0560a848fe9de9c217394a658a6afa406ae86323 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)]
#![warn(clippy::single_char_pattern)]
use std::collections::HashSet;

fn main() {
    let x = "foo";
    x.split("x");
    //~^ single_char_pattern
    x.split("xx");
    x.split('x');

    let y = "x";
    x.split(y);
    x.split("ß");
    x.split("ℝ");
    x.split("💣");
    // Can't use this lint for unicode code points which don't fit in a char
    x.split("❤️");
    x.split_inclusive("x");
    //~^ single_char_pattern
    x.contains("x");
    //~^ single_char_pattern
    x.starts_with("x");
    //~^ single_char_pattern
    x.ends_with("x");
    //~^ single_char_pattern
    x.find("x");
    //~^ single_char_pattern
    x.rfind("x");
    //~^ single_char_pattern
    x.rsplit("x");
    //~^ single_char_pattern
    x.split_terminator("x");
    //~^ single_char_pattern
    x.rsplit_terminator("x");
    //~^ single_char_pattern
    x.splitn(2, "x");
    //~^ single_char_pattern
    x.rsplitn(2, "x");
    //~^ single_char_pattern
    x.split_once("x");
    //~^ single_char_pattern
    x.rsplit_once("x");
    //~^ single_char_pattern
    x.matches("x");
    //~^ single_char_pattern
    x.rmatches("x");
    //~^ single_char_pattern
    x.match_indices("x");
    //~^ single_char_pattern
    x.rmatch_indices("x");
    //~^ single_char_pattern
    x.trim_start_matches("x");
    //~^ single_char_pattern
    x.trim_end_matches("x");
    //~^ single_char_pattern
    x.replace("x", "y");
    //~^ single_char_pattern
    x.replacen("x", "y", 3);
    //~^ single_char_pattern
    // Make sure we escape characters correctly.
    x.split("\n");
    //~^ single_char_pattern
    x.split("'");
    //~^ single_char_pattern
    x.split("\'");
    //~^ single_char_pattern
    // Issue #11973: Don't escape `"` in `'"'`
    x.split("\"");
    //~^ single_char_pattern

    let h = HashSet::<String>::new();
    h.contains("X"); // should not warn

    x.replace(';', ",").split(","); // issue #2978
    //
    //~^^ single_char_pattern
    x.starts_with("\x03"); // issue #2996
    //
    //~^^ single_char_pattern

    // Issue #3204
    const S: &str = "#";
    x.find(S);

    // Raw string
    x.split(r"a");
    //~^ single_char_pattern
    x.split(r#"a"#);
    //~^ single_char_pattern
    x.split(r###"a"###);
    //~^ single_char_pattern
    x.split(r###"'"###);
    //~^ single_char_pattern
    x.split(r###"#"###);
    //~^ single_char_pattern
    // Must escape backslash in raw strings when converting to char #8060
    x.split(r#"\"#);
    //~^ single_char_pattern
    x.split(r"\");
    //~^ single_char_pattern

    // should not warn, the char versions are actually slower in some cases
    x.strip_prefix("x");
    x.strip_suffix("x");
}