]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/single_char_pattern.rs
Auto merge of #78415 - tgnottingham:expn_id_tag_hash, r=Aaron1011
[rust.git] / src / tools / clippy / tests / ui / single_char_pattern.rs
1 // run-rustfix
2
3 #![allow(unused_must_use)]
4
5 use std::collections::HashSet;
6
7 fn main() {
8     let x = "foo";
9     x.split("x");
10     x.split("xx");
11     x.split('x');
12
13     let y = "x";
14     x.split(y);
15     // Not yet testing for multi-byte characters
16     // Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_clippy::single_char_pattern`
17     // should have done this but produced an ICE
18     //
19     // We may not want to suggest changing these anyway
20     // See: https://github.com/rust-lang/rust-clippy/issues/650#issuecomment-184328984
21     x.split("ß");
22     x.split("ℝ");
23     x.split("💣");
24     // Can't use this lint for unicode code points which don't fit in a char
25     x.split("❤️");
26     x.contains("x");
27     x.starts_with("x");
28     x.ends_with("x");
29     x.find("x");
30     x.rfind("x");
31     x.rsplit("x");
32     x.split_terminator("x");
33     x.rsplit_terminator("x");
34     x.splitn(0, "x");
35     x.rsplitn(0, "x");
36     x.matches("x");
37     x.rmatches("x");
38     x.match_indices("x");
39     x.rmatch_indices("x");
40     x.trim_start_matches("x");
41     x.trim_end_matches("x");
42     // Make sure we escape characters correctly.
43     x.split("\n");
44     x.split("'");
45     x.split("\'");
46
47     let h = HashSet::<String>::new();
48     h.contains("X"); // should not warn
49
50     x.replace(";", ",").split(","); // issue #2978
51     x.starts_with("\x03"); // issue #2996
52
53     // Issue #3204
54     const S: &str = "#";
55     x.find(S);
56
57     // Raw string
58     x.split(r"a");
59     x.split(r#"a"#);
60     x.split(r###"a"###);
61     x.split(r###"'"###);
62     x.split(r###"#"###);
63 }