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