needless_pass_by_value: make verbose suggestion

This reduces the number of snippet manipulations, and shows the new
reference in context.
This commit is contained in:
Samuel Tardieu 2025-03-12 06:59:37 +01:00
parent 35e6057e71
commit 417d4e6210
3 changed files with 136 additions and 29 deletions

View file

@ -279,13 +279,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
}
}
let inner_input = peel_hir_ty_options(cx, input);
let before_span = input.span.until(inner_input.span);
let after_span = before_span.shrink_to_hi().to(input.span.shrink_to_hi());
diag.span_suggestion(
input.span,
diag.span_suggestion_verbose(
peel_hir_ty_options(cx, input).span.shrink_to_lo(),
"consider taking a reference instead",
format!("{}&{}", snippet(cx, before_span, "_"), snippet(cx, after_span, "_")),
'&',
Applicability::MaybeIncorrect,
);
};