Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed May 4, 2022
1 parent f37ed5d commit 2b149c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ impl<'tcx> LateLintPass<'tcx> for TrimSplitWhitespace {
span_lint_and_sugg(
cx,
TRIM_SPLIT_WHITESPACE,
split_ws_span.with_lo(trim_span.lo()),
format!("found call to `str::{}` before `str::split_whitespace`", trim_fn_name).as_str(),
format!("remove `{}()`", trim_fn_name).as_str(),
"split_whitespace()".to_string(),
trim_span.with_hi(split_ws_span.lo()),
&format!("found call to `str::{}` before `str::split_whitespace`", trim_fn_name),
&format!("remove `{}()`", trim_fn_name),
String::new(),
Applicability::MachineApplicable,
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/trim_split_whitespace.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(clippy::trim_split_whitespace)]
#![allow(clippy::let_unit_value)]

struct Custom();
struct Custom;
impl Custom {
fn trim(self) -> Self {
self
Expand Down Expand Up @@ -69,7 +69,7 @@ fn main() {
let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint

// Custom
let _ = Custom().trim().split_whitespace(); // should not trigger lint
let _ = Custom.trim().split_whitespace(); // should not trigger lint

// Deref<Target=str>
let s = DerefStr(" A B C ");
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/trim_split_whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(clippy::trim_split_whitespace)]
#![allow(clippy::let_unit_value)]

struct Custom();
struct Custom;
impl Custom {
fn trim(self) -> Self {
self
Expand Down Expand Up @@ -69,7 +69,7 @@ fn main() {
let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint

// Custom
let _ = Custom().trim().split_whitespace(); // should not trigger lint
let _ = Custom.trim().split_whitespace(); // should not trigger lint

// Deref<Target=str>
let s = DerefStr(" A B C ");
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/trim_split_whitespace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,51 @@ error: found call to `str::trim` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:62:23
|
LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim()`: `split_whitespace()`
| ^^^^^^^ help: remove `trim()`
|
= note: `-D clippy::trim-split-whitespace` implied by `-D warnings`

error: found call to `str::trim_start` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:63:23
|
LL | let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim_start()`: `split_whitespace()`
| ^^^^^^^^^^^^^ help: remove `trim_start()`

error: found call to `str::trim_end` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:64:23
|
LL | let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim_end()`: `split_whitespace()`
| ^^^^^^^^^^^ help: remove `trim_end()`

error: found call to `str::trim` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:67:37
|
LL | let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim()`: `split_whitespace()`
| ^^^^^^^ help: remove `trim()`

error: found call to `str::trim_start` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:68:37
|
LL | let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim_start()`: `split_whitespace()`
| ^^^^^^^^^^^^^ help: remove `trim_start()`

error: found call to `str::trim_end` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:69:37
|
LL | let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim_end()`: `split_whitespace()`
| ^^^^^^^^^^^ help: remove `trim_end()`

error: found call to `str::trim` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:76:15
|
LL | let _ = s.trim().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim()`: `split_whitespace()`
| ^^^^^^^ help: remove `trim()`

error: found call to `str::trim` before `str::split_whitespace`
--> $DIR/trim_split_whitespace.rs:84:15
|
LL | let _ = s.trim().split_whitespace(); // should trigger lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `trim()`: `split_whitespace()`
| ^^^^^^^ help: remove `trim()`

error: aborting due to 8 previous errors

0 comments on commit 2b149c2

Please sign in to comment.