Skip to content

Commit 64cd9e4

Browse files
author
BO41
committed
Try to fix .fixed
1 parent 6bbf418 commit 64cd9e4

File tree

5 files changed

+49
-348
lines changed

5 files changed

+49
-348
lines changed

clippy_lints/src/methods/mod.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
10221022
["flat_map", "filter_map"] => lint_filter_map_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
10231023
["flat_map", ..] => lint_flat_map_identity(cx, expr, arg_lists[0], method_spans[0]),
10241024
["flatten", "map"] => lint_map_flatten(cx, expr, arg_lists[1]),
1025-
["is_some", "find"] => lint_search_is_some(cx, expr, "find", arg_lists[1], arg_lists[0]),
1026-
["is_some", "position"] => lint_search_is_some(cx, expr, "position", arg_lists[1], arg_lists[0]),
1027-
["is_some", "rposition"] => lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0]),
1025+
["is_some", "find"] => lint_search_is_some(cx, expr, "find", arg_lists[1], arg_lists[0], method_spans[1]),
1026+
["is_some", "position"] => {
1027+
lint_search_is_some(cx, expr, "position", arg_lists[1], arg_lists[0], method_spans[1])
1028+
},
1029+
["is_some", "rposition"] => {
1030+
lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
1031+
},
10281032
["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
10291033
["as_ptr", "unwrap"] | ["as_ptr", "expect"] => {
10301034
lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0])
@@ -2381,6 +2385,7 @@ fn lint_search_is_some<'a, 'tcx>(
23812385
search_method: &str,
23822386
search_args: &'tcx [hir::Expr],
23832387
is_some_args: &'tcx [hir::Expr],
2388+
method_span: Span,
23842389
) {
23852390
// lint if caller of search is an Iterator
23862391
if match_trait_method(cx, &is_some_args[0], &paths::ITERATOR) {
@@ -2398,15 +2403,13 @@ fn lint_search_is_some<'a, 'tcx>(
23982403
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
23992404
let closure_body = cx.tcx.hir().body(body_id);
24002405
if let Some(closure_arg) = closure_body.params.get(0);
2401-
if let hir::PatKind::Ref(..) = closure_arg.pat.node;
24022406
then {
2403-
match &closure_arg.pat.node {
2404-
hir::PatKind::Ref(..) => Some(search_snippet.replacen('&', "", 1)),
2405-
hir::PatKind::Binding(_, _, expr, _) => {
2406-
let closure_arg_snip = snippet(cx, expr.span, "..");
2407-
Some(search_snippet.replace(&format!("*{}", closure_arg_snip), &closure_arg_snip))
2408-
}
2409-
_ => None,
2407+
if let hir::PatKind::Ref(..) = closure_arg.pat.node {
2408+
Some(search_snippet.replacen('&', "", 1))
2409+
} else if let Some(name) = get_arg_name(&closure_arg.pat) {
2410+
Some(search_snippet.replace(&format!("*{}", name), &name.as_str()))
2411+
} else {
2412+
None
24102413
}
24112414
} else {
24122415
None
@@ -2416,14 +2419,12 @@ fn lint_search_is_some<'a, 'tcx>(
24162419
span_lint_and_sugg(
24172420
cx,
24182421
SEARCH_IS_SOME,
2419-
expr.span,
2422+
method_span.with_hi(expr.span.hi()),
24202423
&msg,
24212424
"try this",
24222425
format!(
24232426
"any({})",
2424-
any_search_snippet
2425-
.as_ref()
2426-
.map_or(&*search_snippet, String::as_str)
2427+
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
24272428
),
24282429
Applicability::MachineApplicable,
24292430
);

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub fn resolve_node(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> Res {
338338
}
339339

340340
/// Returns the method names and argument list of nested method call expressions that make up
341-
/// `expr`.
341+
/// `expr`. method/span lists are sorted with the most recent call first.
342342
pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec<Symbol>, Vec<&[Expr]>, Vec<Span>) {
343343
let mut method_names = Vec::with_capacity(max_depth);
344344
let mut arg_lists = Vec::with_capacity(max_depth);

tests/ui/methods.fixed

-306
This file was deleted.

tests/ui/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// aux-build:option_helpers.rs
22
// compile-flags: --edition 2018
3-
// run-rustfix
43

54
#![warn(clippy::all, clippy::pedantic, clippy::option_unwrap_used)]
65
#![allow(
@@ -267,6 +266,7 @@ fn search_is_some() {
267266
let _ = v.iter().find(|&x| *x < 0).is_some();
268267
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
269268
let _ = (0..1).find(|x| *x == 0).is_some();
269+
let _ = v.iter().find(|x| **x == 0).is_some();
270270

271271
// Check `find().is_some()`, multi-line case.
272272
let _ = v.iter().find(|&x| {

0 commit comments

Comments
 (0)