Skip to content

Commit 563a009

Browse files
committed
apply suggestions
1 parent 56dd532 commit 563a009

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

clippy_lints/src/methods/map_identity.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ pub(super) fn check(
2525
&& let Some(call_span) = expr.span.trim_start(caller.span)
2626
{
2727
let mut sugg = vec![(call_span, String::new())];
28-
let mut apply = true;
29-
if !is_mutable(cx, caller) {
28+
let mut app = Applicability::MachineApplicable;
29+
30+
let needs_to_be_mutable = || cx.typeck_results().expr_ty_adjusted(expr).is_mutable_ptr();
31+
let is_mutable = || is_mutable(cx, caller);
32+
if needs_to_be_mutable() && !is_mutable() {
3033
if let Some(hir_id) = path_to_local_with_projections(caller)
3134
&& let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
3235
&& let PatKind::Binding(_, _, ident, _) = pat.kind
3336
{
37+
// We can reach the binding -- suggest making it mutable
3438
sugg.push((ident.span.shrink_to_lo(), String::from("mut ")));
3539
} else {
36-
// If we can't make the binding mutable, make the suggestion `Unspecified` to prevent it from being
37-
// automatically applied, and add a complementary help message.
38-
apply = false;
40+
// If we can't make the binding mutable, prevent the suggestion from being automatically applied,
41+
// and add a complementary help message.
42+
app = Applicability::Unspecified;
3943
}
4044
}
4145

@@ -53,16 +57,9 @@ pub(super) fn check(
5357
call_span,
5458
"unnecessary map of the identity function",
5559
|diag| {
56-
diag.multipart_suggestion(
57-
format!("remove the call to `{name}`"),
58-
sugg,
59-
if apply {
60-
Applicability::MachineApplicable
61-
} else {
62-
Applicability::Unspecified
63-
},
64-
);
65-
if !apply {
60+
diag.multipart_suggestion(format!("remove the call to `{name}`"), sugg, app);
61+
62+
if app != Applicability::MachineApplicable {
6663
let note = if let Some(method_requiring_mut) = method_requiring_mut {
6764
format!("this must be made mutable to use `{method_requiring_mut}`")
6865
} else {

0 commit comments

Comments
 (0)