Skip to content

Commit 20e4bb9

Browse files
committed
only calculate method_required_mut if necessary
1 parent 51ab495 commit 20e4bb9

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

clippy_lints/src/methods/map_identity.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ pub(super) fn check(
4848
}
4949
}
5050

51-
let method_requiring_mut = if let Node::Expr(expr) = cx.tcx.parent_hir_node(expr.hir_id)
52-
&& let ExprKind::MethodCall(method, ..) = expr.kind
53-
{
54-
Some(method.ident)
55-
} else {
56-
None
57-
};
58-
5951
span_lint_and_then(
6052
cx,
6153
MAP_IDENTITY,
@@ -65,8 +57,10 @@ pub(super) fn check(
6557
diag.multipart_suggestion(msg, sugg, app);
6658

6759
if app != Applicability::MachineApplicable {
68-
let note = if let Some(method_requiring_mut) = method_requiring_mut {
69-
format!("this must be made mutable to use `{method_requiring_mut}`")
60+
let note = if let Node::Expr(expr) = cx.tcx.parent_hir_node(expr.hir_id)
61+
&& let ExprKind::MethodCall(method, ..) = expr.kind
62+
{
63+
format!("this must be made mutable to use `{}`", method.ident)
7064
} else {
7165
"this must be made mutable".to_string()
7266
};

0 commit comments

Comments
 (0)