]> git.lizzy.rs Git - rust.git/blob - tests/ui/single_char_pattern.rs
5277841fe325cabd9553a0db749a45d4537a1faf
[rust.git] / tests / ui / single_char_pattern.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 use std::collections::HashSet;
11
12 fn main() {
13     let x = "foo";
14     x.split("x");
15     x.split("xx");
16     x.split('x');
17
18     let y = "x";
19     x.split(y);
20     // Not yet testing for multi-byte characters
21     // Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_clippy::single_char_pattern`
22     // should have done this but produced an ICE
23     //
24     // We may not want to suggest changing these anyway
25     // See: https://github.com/rust-lang/rust-clippy/issues/650#issuecomment-184328984
26     x.split("ß");
27     x.split("ℝ");
28     x.split("💣");
29     // Can't use this lint for unicode code points which don't fit in a char
30     x.split("❤️");
31     x.contains("x");
32     x.starts_with("x");
33     x.ends_with("x");
34     x.find("x");
35     x.rfind("x");
36     x.rsplit("x");
37     x.split_terminator("x");
38     x.rsplit_terminator("x");
39     x.splitn(0, "x");
40     x.rsplitn(0, "x");
41     x.matches("x");
42     x.rmatches("x");
43     x.match_indices("x");
44     x.rmatch_indices("x");
45     x.trim_left_matches("x");
46     x.trim_right_matches("x");
47     // Make sure we escape characters correctly.
48     x.split("\n");
49
50     let h = HashSet::<String>::new();
51     h.contains("X"); // should not warn
52
53     x.replace(";", ",").split(","); // issue #2978
54     x.starts_with("\x03"); // issue #2996
55
56     // Issue #3204
57     const S: &str = "#";
58     x.find(S);
59 }