Skip to content

Commit

Permalink
Account for Rc and Arc when suggesting to clone
Browse files Browse the repository at this point in the history
When suggesting to clone a reference-counted value, be less uncertain.
  • Loading branch information
estebank committed Aug 4, 2023
1 parent c435af0 commit edc3e26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/moves/use_of_moved_value_clone_suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
| ++++++++
Expand Down

0 comments on commit edc3e26

Please sign in to comment.