Skip to content

Improve help message for search_is_some lint #12140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/search_is_some.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>(
SEARCH_IS_SOME,
method_span.with_hi(expr.span.hi()),
&msg,
"use `any()` instead",
"consider using",
format!(
"any({})",
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
Expand All @@ -77,7 +77,7 @@ pub(super) fn check<'tcx>(
SEARCH_IS_SOME,
expr.span,
&msg,
"use `!_.any()` instead",
"consider using",
format!(
"!{iter}.any({})",
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
Expand Down Expand Up @@ -118,7 +118,7 @@ pub(super) fn check<'tcx>(
SEARCH_IS_SOME,
method_span.with_hi(expr.span.hi()),
&msg,
"use `contains()` instead",
"consider using",
format!("contains({find_arg})"),
applicability,
);
Expand All @@ -132,7 +132,7 @@ pub(super) fn check<'tcx>(
SEARCH_IS_SOME,
expr.span,
&msg,
"use `!_.contains()` instead",
"consider using",
format!("!{string}.contains({find_arg})"),
applicability,
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-9041.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/ice-9041.rs:5:19
|
LL | things.iter().find(|p| is_thing_ready(p)).is_some()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|p| is_thing_ready(&p))`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|p| is_thing_ready(&p))`
|
= note: `-D clippy::search-is-some` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::search_is_some)]`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/search_is_some.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:42:20
|
LL | let _ = (0..1).find(some_closure).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(some_closure)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(some_closure)`

error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:52:13
Expand Down Expand Up @@ -82,7 +82,7 @@ error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:79:13
|
LL | let _ = (0..1).find(some_closure).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(some_closure)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(some_closure)`

error: aborting due to 8 previous errors

Loading