Skip to content

Commit 9857a40

Browse files
committed
refactor: versioning and lint code cleanup
1 parent 637c6c4 commit 9857a40

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,7 @@ declare_clippy_lint! {
43984398
/// }
43994399
/// }
44004400
/// ```
4401-
#[clippy::version = "1.85.0"]
4401+
#[clippy::version = "1.86.0"]
44024402
pub RETURN_AND_THEN,
44034403
style,
44044404
"using `Option::and_then` or `Result::and_then` to chain a computation that returns an `Option` or a `Result`"

clippy_lints/src/methods/return_and_then.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,24 @@ pub(super) fn check<'tcx>(
4040
};
4141

4242
let closure_arg = fn_decl.inputs[0];
43-
let closure_body = cx.tcx.hir().body(body);
44-
let closure_expr = peel_blocks(closure_body.value);
43+
let closure_expr = peel_blocks(cx.tcx.hir().body(body).value);
4544

46-
let msg = "use the question mark operator instead of an `and_then` call";
4745
let mut applicability = Applicability::MachineApplicable;
46+
let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability);
47+
let recv_snip = snippet_with_applicability(cx, recv.span, "..", &mut applicability);
4848
let body_snip = snippet_with_applicability(cx, closure_expr.span, "..", &mut applicability);
4949
let inner = match body_snip.strip_prefix('{').and_then(|s| s.strip_suffix('}')) {
5050
Some(s) => s.trim_start_matches('\n').trim_end(),
5151
None => &body_snip,
5252
};
5353

54+
let msg = "use the question mark operator instead of an `and_then` call";
5455
let sugg = format!(
5556
"let {} = {}?;\n{}",
56-
snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability),
57-
snippet_with_applicability(cx, recv.span, "..", &mut applicability),
57+
arg_snip,
58+
recv_snip,
5859
reindent_multiline(inner.into(), false, indent_of(cx, expr.span))
5960
);
6061

61-
span_lint_and_sugg(
62-
cx,
63-
RETURN_AND_THEN,
64-
expr.span,
65-
msg,
66-
"try",
67-
sugg,
68-
Applicability::MachineApplicable,
69-
);
62+
span_lint_and_sugg(cx, RETURN_AND_THEN, expr.span, msg, "try", sugg, applicability);
7063
}

0 commit comments

Comments
 (0)