Build suggestion within visitor + add more tests

This commit is contained in:
ThibsG 2021-08-18 16:51:34 +02:00
parent 5ed93af9c4
commit b38f173aa3
6 changed files with 359 additions and 298 deletions

View file

@ -1,17 +1,17 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{is_trait_method, strip_pat_refs};
use clippy_utils::{get_parent_expr_for_hir, is_trait_method, strip_pat_refs};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::{self, HirId, HirIdMap, HirIdSet, PatKind};
use rustc_hir::{self, Expr, ExprKind, HirId, PatKind};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::hir::place::ProjectionKind;
use rustc_middle::mir::FakeReadCause;
use rustc_middle::mir::{FakeReadCause, Mutability};
use rustc_middle::ty;
use rustc_span::source_map::Span;
use rustc_span::source_map::{BytePos, Span};
use rustc_span::symbol::sym;
use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
@ -46,42 +46,12 @@ pub(super) fn check<'tcx>(
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_arg.kind;
let closure_body = cx.tcx.hir().body(body_id);
if let Some(closure_arg) = closure_body.params.get(0);
then {
if let hir::PatKind::Ref(..) = closure_arg.pat.kind {
Some((search_snippet.replacen('&', "", 1), None))
Some(search_snippet.replacen('&', "", 1))
} else if let PatKind::Binding(..) = strip_pat_refs(closure_arg.pat).kind {
let mut visitor = DerefDelegate {
cx,
set: HirIdSet::default(),
deref_suggs: HirIdMap::default(),
borrow_suggs: HirIdMap::default()
};
let fn_def_id = cx.tcx.hir().local_def_id(search_arg.hir_id);
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(
&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results()
).consume_body(closure_body);
});
let replacements = if visitor.set.is_empty() {
None
} else {
let mut deref_suggs = Vec::new();
let mut borrow_suggs = Vec::new();
for node in visitor.set {
let span = cx.tcx.hir().span(node);
if let Some(sugg) = visitor.deref_suggs.get(&node) {
deref_suggs.push((span, sugg.clone()));
}
if let Some(sugg) = visitor.borrow_suggs.get(&node) {
borrow_suggs.push((span, sugg.clone()));
}
}
Some((deref_suggs, borrow_suggs))
};
Some((search_snippet.to_string(), replacements))
get_closure_suggestion(cx, search_arg, closure_body)
.or_else(|| Some(search_snippet.to_string()))
} else {
None
}
@ -90,38 +60,35 @@ pub(super) fn check<'tcx>(
}
};
// add note if not multi-line
let (closure_snippet, replacements) = any_search_snippet
.as_ref()
.map_or((&*search_snippet, None), |s| (&s.0, s.1.clone()));
let (span, help, sugg) = if is_some {
(
if is_some {
span_lint_and_sugg(
cx,
SEARCH_IS_SOME,
method_span.with_hi(expr.span.hi()),
&msg,
"use `any()` instead",
format!("any({})", closure_snippet),
)
format!(
"any({})",
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
),
Applicability::MachineApplicable,
);
} else {
let iter = snippet(cx, search_recv.span, "..");
(
span_lint_and_sugg(
cx,
SEARCH_IS_SOME,
expr.span,
&msg,
"use `!_.any()` instead",
format!("!{}.any({})", iter, closure_snippet),
)
};
span_lint_and_then(cx, SEARCH_IS_SOME, span, &msg, |db| {
if let Some((deref_suggs, borrow_suggs)) = replacements {
db.span_suggestion(span, help, sugg, Applicability::MaybeIncorrect);
if !deref_suggs.is_empty() {
db.multipart_suggestion("...and remove deref", deref_suggs, Applicability::MaybeIncorrect);
}
if !borrow_suggs.is_empty() {
db.multipart_suggestion("...and borrow variable", borrow_suggs, Applicability::MaybeIncorrect);
}
} else {
db.span_suggestion(span, help, sugg, Applicability::MachineApplicable);
}
});
format!(
"!{}.any({})",
iter,
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
),
Applicability::MachineApplicable,
);
}
} else {
let hint = format!(
"this is more succinctly expressed by calling `any()`{}",
@ -184,53 +151,86 @@ pub(super) fn check<'tcx>(
}
}
fn get_closure_suggestion<'tcx>(
cx: &LateContext<'_>,
search_arg: &'tcx hir::Expr<'_>,
closure_body: &hir::Body<'_>,
) -> Option<String> {
let mut visitor = DerefDelegate {
cx,
closure_span: search_arg.span,
next_pos: None,
suggestion_start: String::new(),
suggestion_end: String::new(),
};
let fn_def_id = cx.tcx.hir().local_def_id(search_arg.hir_id);
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
.consume_body(closure_body);
});
if visitor.suggestion_start.is_empty() {
None
} else {
Some(format!("{}{}", visitor.suggestion_start, visitor.suggestion_end))
}
}
struct DerefDelegate<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
set: HirIdSet,
deref_suggs: HirIdMap<String>,
borrow_suggs: HirIdMap<String>,
closure_span: Span,
next_pos: Option<BytePos>,
suggestion_start: String,
suggestion_end: String,
}
impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir();
if cmt.place.projections.is_empty() {
self.set.insert(cmt.hir_id);
} else {
let mut replacement_str = map.name(id).to_string();
let last_deref = cmt
.place
.projections
.iter()
.rposition(|proj| proj.kind == ProjectionKind::Deref);
if let Some(pos) = last_deref {
let mut projections = cmt.place.projections.clone();
projections.truncate(pos);
for item in projections {
if item.kind == ProjectionKind::Deref {
replacement_str = format!("*{}", replacement_str);
}
}
self.set.insert(cmt.hir_id);
self.deref_suggs.insert(cmt.hir_id, replacement_str);
}
}
}
}
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir();
if cmt.place.projections.is_empty() {
let replacement_str = format!("&{}", map.name(id).to_string());
self.set.insert(cmt.hir_id);
self.borrow_suggs.insert(cmt.hir_id, replacement_str);
let ident_str = map.name(id).to_string();
let span = map.span(cmt.hir_id);
let start_span = if let Some(next_pos) = self.next_pos {
Span::new(next_pos, span.lo(), span.ctxt())
} else {
let mut replacement_str = map.name(id).to_string();
self.closure_span.until(span)
};
let start_snip = snippet(self.cx, start_span, "..");
let end_span = Span::new(span.hi(), self.closure_span.hi(), span.ctxt());
let end_snip = snippet(self.cx, end_span, "..");
if cmt.place.projections.is_empty() {
self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
} else {
let parent_expr = get_parent_expr_for_hir(self.cx, cmt.hir_id);
if let Some(Expr { hir_id: _, kind, .. }) = parent_expr {
if let ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) = kind {
let args_to_handle = args.iter().filter(|arg| arg.hir_id == cmt.hir_id).collect::<Vec<_>>();
if !args_to_handle.is_empty() {
for arg in &args_to_handle {
let arg_ty_kind = self.cx.typeck_results().expr_ty(arg).kind();
if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
let start_span = if let Some(next_pos) = self.next_pos {
Span::new(next_pos, span.lo(), span.ctxt())
} else {
self.closure_span.until(span)
};
let start_snip = snippet(self.cx, start_span, "..");
self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
self.suggestion_end = end_snip.to_string();
self.next_pos = Some(span.hi());
}
}
return;
}
}
}
let mut replacement_str = ident_str;
let last_deref = cmt
.place
.projections
@ -246,11 +246,13 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
replacement_str = format!("*{}", replacement_str);
}
}
self.set.insert(cmt.hir_id);
self.deref_suggs.insert(cmt.hir_id, replacement_str);
}
self.suggestion_start
.push_str(&format!("{}{}", start_snip, replacement_str));
self.suggestion_end = end_snip.to_string();
}
self.next_pos = Some(span.hi());
}
}

View file

@ -36,11 +36,6 @@ fn main() {
// check that we don't lint if `find()` is called with
// `Pattern` that is not a string
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
// Check `find().is_some()`, single-line case.
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_some();
let _ = v.iter().find(|x| **x == 0).is_some();
}
#[rustfmt::skip]
@ -75,44 +70,4 @@ fn is_none() {
// check that we don't lint if `find()` is called with
// `Pattern` that is not a string
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none();
// Check `find().is_none()`, single-line case.
let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_none();
let _ = v.iter().find(|x| **x == 0).is_none();
}
#[allow(clippy::clone_on_copy, clippy::map_clone)]
mod issue7392 {
struct Player {
hand: Vec<usize>,
}
fn filter() {
let p = Player {
hand: vec![1, 2, 3, 4, 5],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
.map(|c| c.clone())
.collect::<Vec<_>>();
}
struct PlayerTuple {
hand: Vec<(usize, char)>,
}
fn filter_tuple() {
let p = PlayerTuple {
hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none())
.map(|c| c.clone())
.collect::<Vec<_>>();
}
}

View file

@ -35,53 +35,8 @@ LL | | ).is_some();
|
= help: this is more succinctly expressed by calling `any()`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:41:20
|
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `any()` instead
|
LL | let _ = (0..1).any(|x| **y == *x); // one dereference less
| ^^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = (0..1).find(|x| **y == x).is_some(); // one dereference less
| ^
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:42:20
|
LL | let _ = (0..1).find(|x| *x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `any()` instead
|
LL | let _ = (0..1).any(|x| *x == 0);
| ^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = (0..1).find(|x| x == 0).is_some();
| ^
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:43:22
|
LL | let _ = v.iter().find(|x| **x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `any()` instead
|
LL | let _ = v.iter().any(|x| **x == 0);
| ^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = v.iter().find(|x| *x == 0).is_some();
| ^^
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:53:13
--> $DIR/search_is_some.rs:48:13
|
LL | let _ = v.iter().find(|&x| {
| _____________^
@ -93,7 +48,7 @@ LL | | ).is_none();
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `position`
--> $DIR/search_is_some.rs:59:13
--> $DIR/search_is_some.rs:54:13
|
LL | let _ = v.iter().position(|&x| {
| _____________^
@ -105,7 +60,7 @@ LL | | ).is_none();
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `rposition`
--> $DIR/search_is_some.rs:65:13
--> $DIR/search_is_some.rs:60:13
|
LL | let _ = v.iter().rposition(|&x| {
| _____________^
@ -116,80 +71,5 @@ LL | | ).is_none();
|
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:80:13
|
LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `!_.any()` instead
|
LL | let _ = !(0..1).any(|x| **y == *x); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = (0..1).find(|x| **y == x).is_none(); // one dereference less
| ^
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:81:13
|
LL | let _ = (0..1).find(|x| *x == 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `!_.any()` instead
|
LL | let _ = !(0..1).any(|x| *x == 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = (0..1).find(|x| x == 0).is_none();
| ^
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:82:13
|
LL | let _ = v.iter().find(|x| **x == 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `!_.any()` instead
|
LL | let _ = !v.iter().any(|x| **x == 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | let _ = v.iter().find(|x| *x == 0).is_none();
| ^^
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:98:25
|
LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `!_.any()` instead
|
LL | .filter(|c| !filter_hand.iter().any(|cc| c == cc))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: ...and borrow variable
|
LL | .filter(|c| filter_hand.iter().find(|cc| c == &cc).is_none())
| ^^^
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:114:30
|
LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `!_.any()` instead
|
LL | .filter(|(c, _)| !filter_hand.iter().any(|cc| c == *cc))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: ...and remove deref
|
LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == cc).is_none())
| ^^
error: aborting due to 14 previous errors
error: aborting due to 6 previous errors

View file

@ -4,9 +4,19 @@
fn main() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, single-line case.
let _ = v.iter().any(|x| *x < 0);
let _ = (0..1).any(|x| **y == x); // one dereference less
let _ = (0..1).any(|x| x == 0);
let _ = v.iter().any(|x| *x == 0);
let _ = (4..5).any(|x| x == 1 || x == 3 || x == 5);
let _ = (1..3).any(|x| [1, 2, 3].contains(&x));
let _ = (1..3).any(|x| x == 0 || [1, 2, 3].contains(&x));
let _ = (1..3).any(|x| [1, 2, 3].contains(&x) || x == 0);
let _ = (1..3)
.any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1);
// Check `position().is_some()`, single-line case.
let _ = v.iter().any(|&x| x < 0);
@ -32,9 +42,18 @@ fn main() {
fn is_none() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_none()`, single-line case.
let _ = !v.iter().any(|x| *x < 0);
let _ = !(0..1).any(|x| **y == x); // one dereference less
let _ = !(0..1).any(|x| x == 0);
let _ = !v.iter().any(|x| *x == 0);
let _ = !(4..5).any(|x| x == 1 || x == 3 || x == 5);
let _ = !(1..3).any(|x| [1, 2, 3].contains(&x));
let _ = !(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x));
let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0);
let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1);
// Check `position().is_none()`, single-line case.
let _ = !v.iter().any(|&x| x < 0);
@ -58,3 +77,38 @@ fn is_none() {
let _ = !s1[2..].contains(&s2);
let _ = !s1[2..].contains(&s2[2..]);
}
#[allow(clippy::clone_on_copy, clippy::map_clone)]
mod issue7392 {
struct Player {
hand: Vec<usize>,
}
fn filter() {
let p = Player {
hand: vec![1, 2, 3, 4, 5],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|c| !filter_hand.iter().any(|cc| c == &cc))
.map(|c| c.clone())
.collect::<Vec<_>>();
}
struct PlayerTuple {
hand: Vec<(usize, char)>,
}
fn filter_tuple() {
let p = PlayerTuple {
hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|(c, _)| !filter_hand.iter().any(|cc| c == cc))
.map(|c| c.clone())
.collect::<Vec<_>>();
}
}

View file

@ -4,9 +4,20 @@
fn main() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, single-line case.
let _ = v.iter().find(|&x| *x < 0).is_some();
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_some();
let _ = v.iter().find(|x| **x == 0).is_some();
let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some();
let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some();
let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some();
let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some();
let _ = (1..3)
.find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
.is_some();
// Check `position().is_some()`, single-line case.
let _ = v.iter().position(|&x| x < 0).is_some();
@ -32,9 +43,20 @@ fn main() {
fn is_none() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_none()`, single-line case.
let _ = v.iter().find(|&x| *x < 0).is_none();
let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_none();
let _ = v.iter().find(|x| **x == 0).is_none();
let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none();
let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none();
let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none();
let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none();
let _ = (1..3)
.find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
.is_none();
// Check `position().is_none()`, single-line case.
let _ = v.iter().position(|&x| x < 0).is_none();
@ -58,3 +80,38 @@ fn is_none() {
let _ = s1[2..].find(&s2).is_none();
let _ = s1[2..].find(&s2[2..]).is_none();
}
#[allow(clippy::clone_on_copy, clippy::map_clone)]
mod issue7392 {
struct Player {
hand: Vec<usize>,
}
fn filter() {
let p = Player {
hand: vec![1, 2, 3, 4, 5],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
.map(|c| c.clone())
.collect::<Vec<_>>();
}
struct PlayerTuple {
hand: Vec<(usize, char)>,
}
fn filter_tuple() {
let p = PlayerTuple {
hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
};
let filter_hand = vec![5];
let _ = p
.hand
.iter()
.filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none())
.map(|c| c.clone())
.collect::<Vec<_>>();
}
}

View file

@ -1,148 +1,261 @@
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:9:22
--> $DIR/search_is_some_fixable.rs:10:22
|
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`
--> $DIR/search_is_some_fixable.rs:11:20
|
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)`
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: use `any()` instead: `any(|x| x == 0)`
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: use `any()` instead: `any(|x| *x == 0)`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:14:20
|
LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 1 || x == 3 || x == 5)`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:15:20
|
LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| [1, 2, 3].contains(&x))`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:16:20
|
LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0 || [1, 2, 3].contains(&x))`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:17:20
|
LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| [1, 2, 3].contains(&x) || x == 0)`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:19:10
|
LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
| __________^
LL | | .is_some();
| |__________________^ help: use `any()` instead: `any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)`
error: called `is_some()` after searching an `Iterator` with `position`
--> $DIR/search_is_some_fixable.rs:12:22
--> $DIR/search_is_some_fixable.rs:23:22
|
LL | let _ = v.iter().position(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
error: called `is_some()` after searching an `Iterator` with `rposition`
--> $DIR/search_is_some_fixable.rs:15:22
--> $DIR/search_is_some_fixable.rs:26:22
|
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:20:27
--> $DIR/search_is_some_fixable.rs:31:27
|
LL | let _ = "hello world".find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:21:27
--> $DIR/search_is_some_fixable.rs:32:27
|
LL | let _ = "hello world".find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:22:27
--> $DIR/search_is_some_fixable.rs:33:27
|
LL | let _ = "hello world".find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:24:16
--> $DIR/search_is_some_fixable.rs:35:16
|
LL | let _ = s1.find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:25:16
--> $DIR/search_is_some_fixable.rs:36:16
|
LL | let _ = s1.find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:26:16
--> $DIR/search_is_some_fixable.rs:37:16
|
LL | let _ = s1.find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:28:21
--> $DIR/search_is_some_fixable.rs:39:21
|
LL | let _ = s1[2..].find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:29:21
--> $DIR/search_is_some_fixable.rs:40:21
|
LL | let _ = s1[2..].find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:30:21
--> $DIR/search_is_some_fixable.rs:41:21
|
LL | let _ = s1[2..].find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:37:13
--> $DIR/search_is_some_fixable.rs:49:13
|
LL | let _ = v.iter().find(|&x| *x < 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x < 0)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:50:13
|
LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(|x| **y == x)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:51:13
|
LL | let _ = (0..1).find(|x| *x == 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(|x| x == 0)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:52:13
|
LL | let _ = v.iter().find(|x| **x == 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x == 0)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:53:13
|
LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:54:13
|
LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| [1, 2, 3].contains(&x))`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:55:13
|
LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:56:13
|
LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:57:13
|
LL | let _ = (1..3)
| _____________^
LL | | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
LL | | .is_none();
| |__________________^ help: use `!_.any()` instead: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)`
error: called `is_none()` after searching an `Iterator` with `position`
--> $DIR/search_is_some_fixable.rs:40:13
--> $DIR/search_is_some_fixable.rs:62:13
|
LL | let _ = v.iter().position(|&x| x < 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)`
error: called `is_none()` after searching an `Iterator` with `rposition`
--> $DIR/search_is_some_fixable.rs:43:13
--> $DIR/search_is_some_fixable.rs:65:13
|
LL | let _ = v.iter().rposition(|&x| x < 0).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:49:13
--> $DIR/search_is_some_fixable.rs:71:13
|
LL | let _ = "hello world".find("world").is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains("world")`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:50:13
--> $DIR/search_is_some_fixable.rs:72:13
|
LL | let _ = "hello world".find(&s2).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2)`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:51:13
--> $DIR/search_is_some_fixable.rs:73:13
|
LL | let _ = "hello world".find(&s2[2..]).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2[2..])`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:53:13
--> $DIR/search_is_some_fixable.rs:75:13
|
LL | let _ = s1.find("world").is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains("world")`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:54:13
--> $DIR/search_is_some_fixable.rs:76:13
|
LL | let _ = s1.find(&s2).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2)`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:55:13
--> $DIR/search_is_some_fixable.rs:77:13
|
LL | let _ = s1.find(&s2[2..]).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2[2..])`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:57:13
--> $DIR/search_is_some_fixable.rs:79:13
|
LL | let _ = s1[2..].find("world").is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains("world")`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:58:13
--> $DIR/search_is_some_fixable.rs:80:13
|
LL | let _ = s1[2..].find(&s2).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2)`
error: called `is_none()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:59:13
--> $DIR/search_is_some_fixable.rs:81:13
|
LL | let _ = s1[2..].find(&s2[2..]).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2[2..])`
error: aborting due to 24 previous errors
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:97:25
|
LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == &cc)`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:113:30
|
LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == cc)`
error: aborting due to 42 previous errors