blob: dae04ac4a62d5fd05fee7d6bd6051bb760c3cf75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#![allow(clippy::needless_if, dead_code, unused_must_use, clippy::double_ended_iterator_last)]
fn main() {}
#[allow(clippy::unnecessary_operation)]
fn starts_with() {
"".chars().next() == Some(' ');
//~^ chars_next_cmp
Some(' ') != "".chars().next();
//~^ chars_next_cmp
// Ensure that suggestion is escaped correctly
"".chars().next() == Some('\n');
//~^ chars_next_cmp
Some('\n') != "".chars().next();
//~^ chars_next_cmp
}
fn chars_cmp_with_unwrap() {
let s = String::from("foo");
if s.chars().next().unwrap() == 'f' {
//~^ chars_next_cmp
// s.starts_with('f')
// Nothing here
}
if s.chars().next_back().unwrap() == 'o' {
//~^ chars_last_cmp
// s.ends_with('o')
// Nothing here
}
if s.chars().last().unwrap() == 'o' {
//~^ chars_last_cmp
// s.ends_with('o')
// Nothing here
}
if s.chars().next().unwrap() != 'f' {
//~^ chars_next_cmp
// !s.starts_with('f')
// Nothing here
}
if s.chars().next_back().unwrap() != 'o' {
//~^ chars_last_cmp
// !s.ends_with('o')
// Nothing here
}
if s.chars().last().unwrap() != '\n' {
//~^ chars_last_cmp
// !s.ends_with('o')
// Nothing here
}
}
#[allow(clippy::unnecessary_operation)]
fn ends_with() {
"".chars().last() == Some(' ');
//~^ chars_last_cmp
Some(' ') != "".chars().last();
//~^ chars_last_cmp
"".chars().next_back() == Some(' ');
//~^ chars_last_cmp
Some(' ') != "".chars().next_back();
//~^ chars_last_cmp
// Ensure that suggestion is escaped correctly
"".chars().last() == Some('\n');
//~^ chars_last_cmp
Some('\n') != "".chars().last();
//~^ chars_last_cmp
}
|