]> git.lizzy.rs Git - rust.git/commitdiff
Cleaned up message and suggestion for `lint_search_is_some`
authorRyan Sullivant <rsulli55@gmail.com>
Sat, 7 Nov 2020 07:21:22 +0000 (00:21 -0700)
committerRyan Sullivant <rsulli55@gmail.com>
Wed, 11 Nov 2020 06:18:48 +0000 (23:18 -0700)
clippy_lints/src/methods/mod.rs
tests/ui/search_is_some.stderr
tests/ui/search_is_some_fixable.stderr

index 19e63fbddf74fe2b585d6d6043c2f79be36bb35d..66f5aa0c6a00a97dfa722ce576502cceccf7ce95 100644 (file)
@@ -3053,10 +3053,10 @@ fn lint_search_is_some<'tcx>(
     // lint if caller of search is an Iterator
     if match_trait_method(cx, &is_some_args[0], &paths::ITERATOR) {
         let msg = format!(
-            "called `is_some()` after searching an `Iterator` with {}. This is more succinctly \
-             expressed by calling `any()`.",
+            "called `is_some()` after searching an `Iterator` with {}",
             search_method
         );
+        let hint = "this is more succinctly expressed by calling `any()`";
         let search_snippet = snippet(cx, search_args[1].span, "..");
         if search_snippet.lines().count() <= 1 {
             // suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
@@ -3084,7 +3084,7 @@ fn lint_search_is_some<'tcx>(
                 SEARCH_IS_SOME,
                 method_span.with_hi(expr.span.hi()),
                 &msg,
-                "try this",
+                "use `any()` instead",
                 format!(
                     "any({})",
                     any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
@@ -3092,7 +3092,7 @@ fn lint_search_is_some<'tcx>(
                 Applicability::MachineApplicable,
             );
         } else {
-            span_lint(cx, SEARCH_IS_SOME, expr.span, &msg);
+            span_lint_and_help(cx, SEARCH_IS_SOME, expr.span, &msg, None, hint);
         }
     }
     // lint if `find()` is called by `String` or `&str`
@@ -3109,9 +3109,7 @@ fn lint_search_is_some<'tcx>(
             if is_string_or_str_slice(&search_args[0]);
             if is_string_or_str_slice(&search_args[1]);
             then {
-                let msg = "called `is_some()` after calling `find()` \
-                    on a string. This is more succinctly expressed by calling \
-                    `contains()`.";
+                let msg = "called `is_some()` after calling `find()` on a string";
                 let mut applicability = Applicability::MachineApplicable;
                 let find_arg = snippet_with_applicability(cx, search_args[1].span, "..", &mut applicability);
                 span_lint_and_sugg(
@@ -3119,7 +3117,7 @@ fn lint_search_is_some<'tcx>(
                     SEARCH_IS_SOME,
                     method_span.with_hi(expr.span.hi()),
                     msg,
-                    "try this",
+                    "use `contains()` instead",
                     format!("contains({})", find_arg),
                     applicability,
                 );
index a124ab1dfd44e40401f32be4ce4b1ef150718a9c..43827a6a98dc2b42c1a901d25c5970bcdb08a9ba 100644 (file)
@@ -1,4 +1,4 @@
-error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with find
   --> $DIR/search_is_some.rs:13:13
    |
 LL |       let _ = v.iter().find(|&x| {
@@ -9,8 +9,9 @@ LL | |                    ).is_some();
    | |______________________________^
    |
    = note: `-D clippy::search-is-some` implied by `-D warnings`
+   = help: this is more succinctly expressed by calling `any()`
 
-error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with position
   --> $DIR/search_is_some.rs:19:13
    |
 LL |       let _ = v.iter().position(|&x| {
@@ -19,8 +20,10 @@ LL | |                                   x < 0
 LL | |                               }
 LL | |                    ).is_some();
    | |______________________________^
+   |
+   = help: this is more succinctly expressed by calling `any()`
 
-error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with rposition
   --> $DIR/search_is_some.rs:25:13
    |
 LL |       let _ = v.iter().rposition(|&x| {
@@ -29,6 +32,8 @@ LL | |                                    x < 0
 LL | |                                }
 LL | |                    ).is_some();
    | |______________________________^
+   |
+   = help: this is more succinctly expressed by calling `any()`
 
 error: use of a blacklisted/placeholder name `foo`
   --> $DIR/search_is_some.rs:31:9
index 7a2c063fee82cdc323a676af89cdb2cb2fb12fd8..f4c5d7a3389fe647618a452252fe77f1f78cd9aa 100644 (file)
@@ -1,94 +1,94 @@
-error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with find
   --> $DIR/search_is_some_fixable.rs:10:22
    |
 LL |     let _ = v.iter().find(|&x| *x < 0).is_some();
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)`
    |
    = note: `-D clippy::search-is-some` implied by `-D warnings`
 
-error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with find
   --> $DIR/search_is_some_fixable.rs:11:20
    |
 LL |     let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
-   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)`
 
-error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with find
   --> $DIR/search_is_some_fixable.rs:12:20
    |
 LL |     let _ = (0..1).find(|x| *x == 0).is_some();
-   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0)`
 
-error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with find
   --> $DIR/search_is_some_fixable.rs:13:22
    |
 LL |     let _ = v.iter().find(|x| **x == 0).is_some();
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x == 0)`
 
-error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with position
   --> $DIR/search_is_some_fixable.rs:16:22
    |
 LL |     let _ = v.iter().position(|&x| x < 0).is_some();
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
 
-error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
+error: called `is_some()` after searching an `Iterator` with rposition
   --> $DIR/search_is_some_fixable.rs:19:22
    |
 LL |     let _ = v.iter().rposition(|&x| x < 0).is_some();
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:24:27
    |
 LL |     let _ = "hello world".find("world").is_some();
-   |                           ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
+   |                           ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:25:27
    |
 LL |     let _ = "hello world".find(&s2).is_some();
-   |                           ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
+   |                           ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:26:27
    |
 LL |     let _ = "hello world".find(&s2[2..]).is_some();
-   |                           ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
+   |                           ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:28:16
    |
 LL |     let _ = s1.find("world").is_some();
-   |                ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
+   |                ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:29:16
    |
 LL |     let _ = s1.find(&s2).is_some();
-   |                ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
+   |                ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:30:16
    |
 LL |     let _ = s1.find(&s2[2..]).is_some();
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
+   |                ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:32:21
    |
 LL |     let _ = s1[2..].find("world").is_some();
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:33:21
    |
 LL |     let _ = s1[2..].find(&s2).is_some();
-   |                     ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
+   |                     ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
 
-error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
+error: called `is_some()` after calling `find()` on a string
   --> $DIR/search_is_some_fixable.rs:34:21
    |
 LL |     let _ = s1[2..].find(&s2[2..]).is_some();
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
 
 error: aborting due to 15 previous errors