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