diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index dca4d84f6b1..98ad7f3866f 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -248,7 +248,6 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id); let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind(); - // Note: this should always be true, as `find` only gives us a reference which are not mutable if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) { let start_span = Span::new(self.next_pos, span.lo(), span.ctxt()); let start_snip = @@ -261,10 +260,10 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { }; self.suggestion_start.push_str(&ident_sugg); self.next_pos = span.hi(); + return; } else { self.applicability = Applicability::Unspecified; } - return; } } diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 811bb1e3176..c7c0b766015 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -102,10 +102,17 @@ mod issue7392 { *x == 9 } + fn simple_fn(x: u32) -> bool { + x == 78 + } + fn more_projections() { let x = 19; let ppx: &u32 = &x; let _ = ![ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); let _ = ![String::from("Hey hey")].iter().any(|s| s.len() == 2); + + let v = vec![3, 2, 1, 0]; + let _ = !v.iter().any(|x| simple_fn(*x)); } } diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index c6fbb5e2d26..6b41da4f2f8 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -106,10 +106,17 @@ fn please(x: &u32) -> bool { *x == 9 } + fn simple_fn(x: u32) -> bool { + x == 78 + } + fn more_projections() { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); + + let v = vec![3, 2, 1, 0]; + let _ = v.iter().find(|x| simple_fn(**x)).is_none(); } } diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index b89ddabee55..4313a2d526c 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -170,16 +170,22 @@ LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:112:17 + --> $DIR/search_is_some_fixable_none.rs:116:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:113:17 + --> $DIR/search_is_some_fixable_none.rs:117:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` -error: aborting due to 28 previous errors +error: called `is_none()` after searching an `Iterator` with `find` + --> $DIR/search_is_some_fixable_none.rs:120:17 + | +LL | let _ = v.iter().find(|x| simple_fn(**x)).is_none(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| simple_fn(*x))` + +error: aborting due to 29 previous errors diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index 76b7f3d05d5..833168cf242 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -103,10 +103,17 @@ mod issue7392 { *x == 9 } + fn simple_fn(x: u32) -> bool { + x == 78 + } + fn more_projections() { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); let _ = [String::from("Hey hey")].iter().any(|s| s.len() == 2); + + let v = vec![3, 2, 1, 0]; + let _ = v.iter().any(|x| simple_fn(*x)); } } diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index 364250e6ed8..f9fb241de3f 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -105,10 +105,17 @@ fn please(x: &u32) -> bool { *x == 9 } + fn simple_fn(x: u32) -> bool { + x == 78 + } + fn more_projections() { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); + + let v = vec![3, 2, 1, 0]; + let _ = v.iter().find(|x| simple_fn(**x)).is_some(); } } diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index 183d99497ac..01b13cea2cd 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -161,16 +161,22 @@ LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:111:30 + --> $DIR/search_is_some_fixable_some.rs:115:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:112:50 + --> $DIR/search_is_some_fixable_some.rs:116:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s.len() == 2)` -error: aborting due to 28 previous errors +error: called `is_some()` after searching an `Iterator` with `find` + --> $DIR/search_is_some_fixable_some.rs:119:26 + | +LL | let _ = v.iter().find(|x| simple_fn(**x)).is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| simple_fn(*x))` + +error: aborting due to 29 previous errors