From 0b3ebb546fac5de6be624d335abb3c5f7ad82c74 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sat, 11 May 2024 07:11:36 -0500 Subject: [PATCH] Add note about possible allocation-sharing to Arc/Rc::default. --- library/alloc/src/ffi/c_str.rs | 4 ++++ library/alloc/src/rc.rs | 4 ++++ library/alloc/src/sync.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 19dd90eb81f..3b56a5717e2 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -914,6 +914,8 @@ impl From<&CStr> for Rc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Arc { /// Creates an empty CStr inside an Arc + /// + /// This may or may not share an allocation with other Arcs. #[inline] fn default() -> Self { let c_str: &CStr = Default::default(); @@ -925,6 +927,8 @@ impl Default for Arc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Rc { /// Creates an empty CStr inside an Rc + /// + /// This may or may not share an allocation with other Rcs on the same thread. #[inline] fn default() -> Self { let c_str: &CStr = Default::default(); diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 206489876e3..dddd0603a15 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2228,6 +2228,8 @@ impl Default for Rc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Rc { /// Creates an empty str inside an Rc + /// + /// This may or may not share an allocation with other Rcs on the same thread. #[inline] fn default() -> Self { Rc::from("") @@ -2238,6 +2240,8 @@ impl Default for Rc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Rc<[T]> { /// Creates an empty `[T]` inside an Rc + /// + /// This may or may not share an allocation with other Rcs on the same thread. #[inline] fn default() -> Self { let arr: [T; 0] = []; diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 5f6ce80e194..f06994f7c40 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3304,6 +3304,8 @@ impl Default for Arc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Arc { /// Creates an empty str inside an Arc + /// + /// This may or may not share an allocation with other Arcs. #[inline] fn default() -> Self { Arc::from("") @@ -3314,6 +3316,8 @@ impl Default for Arc { #[stable(feature = "more_rc_default_impls", since = "CURRENT_RUSTC_VERSION")] impl Default for Arc<[T]> { /// Creates an empty `[T]` inside an Arc + /// + /// This may or may not share an allocation with other Arcs. #[inline] fn default() -> Self { let arr: [T; 0] = [];