about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-08-04 17:50:12 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-08-04 17:50:12 +0000
commitedc3e2677335f930450f3e9f006e87869fe31d0c (patch)
tree6d640eb53f3240e8e319b72a9af3cbfc902fe09e /compiler
parentc435af0d5c47a333c7cb7f359f3586d5c9dab3ab (diff)
downloadrust-edc3e2677335f930450f3e9f006e87869fe31d0c.tar.gz
rust-edc3e2677335f930450f3e9f006e87869fe31d0c.zip
Account for `Rc` and `Arc` when suggesting to clone
When suggesting to clone a reference-counted value, be less uncertain.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 03b90f4ab18..4cb6b028e55 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,
             );