Skip to content

Commit

Permalink
Rollup merge of #114477 - estebank:arc-clone, r=compiler-errors
Browse files Browse the repository at this point in the history
Account for `Rc` and `Arc` when suggesting to clone

When suggesting to clone a reference-counted value, be less uncertain.
  • Loading branch information
matthiaskrgr authored Aug 4, 2023
2 parents cd5317a + edc3e26 commit 35b2713
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 35b2713

Please sign in to comment.