- span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |diag| {
- if let Some(snippet) = snippet_opt(cx, caller.span) {
+ span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
+ if let Some(mut snippet) = snippet_opt(cx, caller.span) {
+ if_chain! {
+ if let ty::Closure(_, substs) = fn_ty.kind();
+ if let ClosureKind::FnMut = substs.as_closure().kind();
+ if UsedAfterExprVisitor::is_found(cx, caller)
+ || get_enclosing_loop_or_closure(cx.tcx, expr).is_some();
+
+ then {
+ // Mutable closure is used after current expr; we cannot consume it.
+ snippet = format!("&mut {}", snippet);
+ }
+ }