about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-05-07 00:29:22 +0000
committerGitHub <noreply@github.com>2025-05-07 00:29:22 +0000
commit25631ff0931f68057ff826208ca1caaaed294057 (patch)
tree5f9b75b7930c6ee21cad8b303b67f304f496f07e
parentb7199a69d63bd7bed248a5ab64eef0a83ea632bf (diff)
parent6a4af821b00a1e55f44c80846c1a438a3c41dee5 (diff)
downloadrust-25631ff0931f68057ff826208ca1caaaed294057.tar.gz
rust-25631ff0931f68057ff826208ca1caaaed294057.zip
Rollup merge of #140483 - baumanj:patch-1, r=workingjubilee
Comment on `Rc` abort-guard strategy without naming unrelated fn

`wrapped_add` is used, not `checked_add`, so avoid mentioning specific fn calls that may vary slightly based on "whatever produces the best code" and focus on things that will remain constant into the future.
-rw-r--r--library/alloc/src/rc.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index 619d9f258e3..4b8ea708e7e 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -3536,11 +3536,11 @@ impl<T> Default for Weak<T> {
     }
 }
 
-// NOTE: We checked_add here to deal with mem::forget safely. In particular
-// if you mem::forget Rcs (or Weaks), the ref-count can overflow, and then
-// you can free the allocation while outstanding Rcs (or Weaks) exist.
-// We abort because this is such a degenerate scenario that we don't care about
-// what happens -- no real program should ever experience this.
+// NOTE: If you mem::forget Rcs (or Weaks), drop is skipped and the ref-count
+// is not decremented, meaning the ref-count can overflow, and then you can
+// free the allocation while outstanding Rcs (or Weaks) exist, which would be
+// unsound. We abort because this is such a degenerate scenario that we don't
+// care about what happens -- no real program should ever experience this.
 //
 // This should have negligible overhead since you don't actually need to
 // clone these much in Rust thanks to ownership and move-semantics.