Improve needless_pass_by_value suggestion
This commit is contained in:
parent
f83c94cb3a
commit
79013f813d
3 changed files with 24 additions and 3 deletions
|
|
@ -279,10 +279,18 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
|||
}
|
||||
}
|
||||
|
||||
let suggestion = if is_type_diagnostic_item(cx, ty, sym::Option)
|
||||
&& let snip = snippet(cx, input.span, "_")
|
||||
&& let Some((first, rest)) = snip.split_once('<')
|
||||
{
|
||||
format!("{first}<&{rest}")
|
||||
} else {
|
||||
format!("&{}", snippet(cx, input.span, "_"))
|
||||
};
|
||||
diag.span_suggestion(
|
||||
input.span,
|
||||
"consider taking a reference instead",
|
||||
format!("&{}", snippet(cx, input.span, "_")),
|
||||
suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue