You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #6942 - mgacek8:issue_6815_search_is_none, r=llogiq
search_is_some: add checking for `is_none()`
fixes: #6815
changelog: search_is_some: add checking for `is_none()`.
To be honest I don't know what is the process of renaming the lints. Appreciate any feedback if that needs to be handled differently. Thanks!
Copy file name to clipboardExpand all lines: clippy_lints/src/methods/mod.rs
+46-11
Original file line number
Diff line number
Diff line change
@@ -588,26 +588,31 @@ declare_clippy_lint! {
588
588
589
589
declare_clippy_lint!{
590
590
/// **What it does:** Checks for an iterator or string search (such as `find()`,
591
-
/// `position()`, or `rposition()`) followed by a call to `is_some()`.
591
+
/// `position()`, or `rposition()`) followed by a call to `is_some()` or `is_none()`.
592
592
///
593
-
/// **Why is this bad?** Readability, this can be written more concisely as
594
-
/// `_.any(_)` or `_.contains(_)`.
593
+
/// **Why is this bad?** Readability, this can be written more concisely as:
594
+
/// * `_.any(_)`, or `_.contains(_)` for `is_some()`,
595
+
/// * `!_.any(_)`, or `!_.contains(_)` for `is_none()`.
595
596
///
596
597
/// **Known problems:** None.
597
598
///
598
599
/// **Example:**
599
600
/// ```rust
600
-
/// # let vec = vec![1];
601
+
/// let vec = vec![1];
601
602
/// vec.iter().find(|x| **x == 0).is_some();
603
+
///
604
+
/// let _ = "hello world".find("world").is_none();
602
605
/// ```
603
606
/// Could be written as
604
607
/// ```rust
605
-
/// # let vec = vec![1];
608
+
/// let vec = vec![1];
606
609
/// vec.iter().any(|x| *x == 0);
610
+
///
611
+
/// let _ = !"hello world".contains("world");
607
612
/// ```
608
613
pubSEARCH_IS_SOME,
609
614
complexity,
610
-
"using an iterator or string search followed by `is_some()`, which is more succinctly expressed as a call to `any()` or `contains()`"
615
+
"using an iterator or string search followed by `is_some()` or `is_none()`, which is more succinctly expressed as a call to `any()` or `contains()` (with negation in case of `is_none()`)"
611
616
}
612
617
613
618
declare_clippy_lint!{
@@ -1720,12 +1725,42 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
0 commit comments