Account for Rc and Arc when suggesting to clone

When suggesting to clone a reference-counted value, be less uncertain.
This commit is contained in:
Esteban Küber 2023-08-04 17:50:12 +00:00
parent c435af0d5c
commit edc3e26773
2 changed files with 12 additions and 2 deletions

View File

@ -751,9 +751,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
)
.must_apply_modulo_regions()
{
let msg = if let ty::Adt(def, _) = ty.kind()
&& [
tcx.get_diagnostic_item(sym::Arc),
tcx.get_diagnostic_item(sym::Rc),
].contains(&Some(def.did()))
{
"clone the value to increment its reference count"
} else {
"consider cloning the value if the performance cost is acceptable"
};
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider cloning the value if the performance cost is acceptable",
msg,
suggestion,
Applicability::MachineApplicable,
);

View File

@ -8,7 +8,7 @@ LL | (t, t)
| |
| value moved here
|
help: consider cloning the value if the performance cost is acceptable
help: clone the value to increment its reference count
|
LL | (t.clone(), t)
| ++++++++