about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-04 21:32:00 +0200
committerGitHub <noreply@github.com>2023-08-04 21:32:00 +0200
commit35b271306f5d5912a3440238dbe9888062fe9e24 (patch)
tree316f3b61e1d1acbe729a675c71ec7a0b10506d5f
parentcd5317a00032dd9082cc1e73c43edbd256681f88 (diff)
parentedc3e2677335f930450f3e9f006e87869fe31d0c (diff)
downloadrust-35b271306f5d5912a3440238dbe9888062fe9e24.tar.gz
rust-35b271306f5d5912a3440238dbe9888062fe9e24.zip
Rollup merge of #114477 - estebank:arc-clone, r=compiler-errors
Account for `Rc` and `Arc` when suggesting to clone

When suggesting to clone a reference-counted value, be less uncertain.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs12
-rw-r--r--tests/ui/moves/use_of_moved_value_clone_suggestions.stderr2
2 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 28c0a444fc8..fe4a45b3898 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -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,
             );
diff --git a/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr b/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr
index 22e7951dbe3..0bb486a8893 100644
--- a/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr
+++ b/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr
@@ -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)
    |       ++++++++