Skip to content

Commit

Permalink
Auto merge of rust-lang#12140 - GuillaumeGomez:improve-message-search…
Browse files Browse the repository at this point in the history
…_is_some, r=llogiq

Improve help message for `search_is_some` lint

Fixes rust-lang#11681.

Like mentioned in the issue, we tend to use the formulation "consider using", which we didn't in this case. I think it clears both the confusion and also makes help message more coherent overall.

r? `@llogiq`

changelog: Improve help message for `search_is_some` lint
  • Loading branch information
bors committed Jan 12, 2024
2 parents 7eca5af + 37947ff commit a71211d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 97 deletions.
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

0 comments on commit a71211d

Please sign in to comment.