mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
Add run-rustfix to starts_ends_with
This commit is contained in:
parent
2d11a440dd
commit
d3c452265f
3 changed files with 60 additions and 13 deletions
46
tests/ui/starts_ends_with.fixed
Normal file
46
tests/ui/starts_ends_with.fixed
Normal file
|
@ -0,0 +1,46 @@
|
|||
// run-rustfix
|
||||
#![allow(dead_code, unused_must_use)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn starts_with() {
|
||||
"".starts_with(' ');
|
||||
!"".starts_with(' ');
|
||||
}
|
||||
|
||||
fn chars_cmp_with_unwrap() {
|
||||
let s = String::from("foo");
|
||||
if s.starts_with('f') {
|
||||
// s.starts_with('f')
|
||||
// Nothing here
|
||||
}
|
||||
if s.ends_with('o') {
|
||||
// s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if s.ends_with('o') {
|
||||
// s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.starts_with('f') {
|
||||
// !s.starts_with('f')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.ends_with('o') {
|
||||
// !s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
if !s.ends_with('o') {
|
||||
// !s.ends_with('o')
|
||||
// Nothing here
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_operation)]
|
||||
fn ends_with() {
|
||||
"".ends_with(' ');
|
||||
!"".ends_with(' ');
|
||||
"".ends_with(' ');
|
||||
!"".ends_with(' ');
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(dead_code)]
|
||||
// run-rustfix
|
||||
#![allow(dead_code, unused_must_use)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:7:5
|
||||
--> $DIR/starts_ends_with.rs:8:5
|
||||
|
|
||||
LL | "".chars().next() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')`
|
||||
|
@ -7,19 +7,19 @@ LL | "".chars().next() == Some(' ');
|
|||
= note: `-D clippy::chars-next-cmp` implied by `-D warnings`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:8:5
|
||||
--> $DIR/starts_ends_with.rs:9:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:13:8
|
||||
--> $DIR/starts_ends_with.rs:14:8
|
||||
|
|
||||
LL | if s.chars().next().unwrap() == 'f' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:17:8
|
||||
--> $DIR/starts_ends_with.rs:18:8
|
||||
|
|
||||
LL | if s.chars().next_back().unwrap() == 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
|
||||
|
@ -27,49 +27,49 @@ LL | if s.chars().next_back().unwrap() == 'o' {
|
|||
= note: `-D clippy::chars-last-cmp` implied by `-D warnings`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:21:8
|
||||
--> $DIR/starts_ends_with.rs:22:8
|
||||
|
|
||||
LL | if s.chars().last().unwrap() == 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
|
||||
|
||||
error: you should use the `starts_with` method
|
||||
--> $DIR/starts_ends_with.rs:25:8
|
||||
--> $DIR/starts_ends_with.rs:26:8
|
||||
|
|
||||
LL | if s.chars().next().unwrap() != 'f' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:29:8
|
||||
--> $DIR/starts_ends_with.rs:30:8
|
||||
|
|
||||
LL | if s.chars().next_back().unwrap() != 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:33:8
|
||||
--> $DIR/starts_ends_with.rs:34:8
|
||||
|
|
||||
LL | if s.chars().last().unwrap() != 'o' {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:41:5
|
||||
--> $DIR/starts_ends_with.rs:42:5
|
||||
|
|
||||
LL | "".chars().last() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:42:5
|
||||
--> $DIR/starts_ends_with.rs:43:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().last();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:43:5
|
||||
--> $DIR/starts_ends_with.rs:44:5
|
||||
|
|
||||
LL | "".chars().next_back() == Some(' ');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
|
||||
|
||||
error: you should use the `ends_with` method
|
||||
--> $DIR/starts_ends_with.rs:44:5
|
||||
--> $DIR/starts_ends_with.rs:45:5
|
||||
|
|
||||
LL | Some(' ') != "".chars().next_back();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
|
||||
|
|
Loading…
Reference in a new issue