Improve needless_pass_by_value suggestion (#13880)
Fixes https://github.com/rust-lang/rust-clippy/issues/13744. A simple check to check if the type is an `Option` allows to improve the suggestion. changelog: Improve `needless_pass_by_value` suggestion
This commit is contained in:
commit
a25cbd50ca
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