]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/starts_ends_with.rs
Auto merge of #102536 - scottmcm:lookup_line-tweak, r=jackh726
[rust.git] / src / tools / clippy / tests / ui / starts_ends_with.rs
1 // run-rustfix
2 #![allow(dead_code, unused_must_use)]
3
4 fn main() {}
5
6 #[allow(clippy::unnecessary_operation)]
7 fn starts_with() {
8     "".chars().next() == Some(' ');
9     Some(' ') != "".chars().next();
10
11     // Ensure that suggestion is escaped correctly
12     "".chars().next() == Some('\n');
13     Some('\n') != "".chars().next();
14 }
15
16 fn chars_cmp_with_unwrap() {
17     let s = String::from("foo");
18     if s.chars().next().unwrap() == 'f' {
19         // s.starts_with('f')
20         // Nothing here
21     }
22     if s.chars().next_back().unwrap() == 'o' {
23         // s.ends_with('o')
24         // Nothing here
25     }
26     if s.chars().last().unwrap() == 'o' {
27         // s.ends_with('o')
28         // Nothing here
29     }
30     if s.chars().next().unwrap() != 'f' {
31         // !s.starts_with('f')
32         // Nothing here
33     }
34     if s.chars().next_back().unwrap() != 'o' {
35         // !s.ends_with('o')
36         // Nothing here
37     }
38     if s.chars().last().unwrap() != '\n' {
39         // !s.ends_with('o')
40         // Nothing here
41     }
42 }
43
44 #[allow(clippy::unnecessary_operation)]
45 fn ends_with() {
46     "".chars().last() == Some(' ');
47     Some(' ') != "".chars().last();
48     "".chars().next_back() == Some(' ');
49     Some(' ') != "".chars().next_back();
50
51     // Ensure that suggestion is escaped correctly
52     "".chars().last() == Some('\n');
53     Some('\n') != "".chars().last();
54 }