From ddb35b726a1d735d4bd6822f35e9956d31fcba1b Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:38:43 +0800 Subject: [PATCH 01/13] Update sync.rs --- library/alloc/src/sync.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 9d478a302e96c..53778e4ba1404 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -759,6 +759,16 @@ impl Arc { Self::from_ptr(arc_ptr) } } + + pub fn clone_raw(ptr: *const T) -> Self { + let result = unsafe { + Arc::from_raw(ptr) + }; + + std::mem::forget(result.clone()) + + result + } /// Creates a new [`Weak`] pointer to this allocation. /// From e0857bf6dc8c06b279f7e581119ea402e457e884 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:42:58 +0800 Subject: [PATCH 02/13] Update rc.rs --- library/alloc/src/rc.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a96be57143d38..5a1517fe63156 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -742,6 +742,17 @@ impl Rc { unsafe { Self::from_ptr(rc_ptr) } } + + /// Obtains a new reference two a raw [`Rc`] pointer, without taking ownership. + pub unsafe fn clone_raw(ptr: *const T) -> Self { + let result = unsafe { + Rc::from_raw(ptr) + }; + + std::mem::forget(result.clone()) + + result + } /// Creates a new [`Weak`] pointer to this allocation. /// From 33cc1ce2d781a5028277b5fb88c419de09fcf9ac Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:44:03 +0800 Subject: [PATCH 03/13] Update sync.rs --- library/alloc/src/sync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 53778e4ba1404..2852640fd226d 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -760,6 +760,7 @@ impl Arc { } } + /// Obtains a new reference to a raw [`Arc`] pointer, without taking ownership. pub fn clone_raw(ptr: *const T) -> Self { let result = unsafe { Arc::from_raw(ptr) From 4ac1f00510d1b772ea20804e14877501a7a89290 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:50:21 +0800 Subject: [PATCH 04/13] Update sync.rs --- library/alloc/src/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 2852640fd226d..da0fddc69c71f 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -766,7 +766,7 @@ impl Arc { Arc::from_raw(ptr) }; - std::mem::forget(result.clone()) + std::mem::forget(result.clone()); result } From 304662a17cf7843c6553f6dc933dada23064c79e Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:51:50 +0800 Subject: [PATCH 05/13] Update rc.rs --- library/alloc/src/rc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 5a1517fe63156..0b15db911a818 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -749,7 +749,7 @@ impl Rc { Rc::from_raw(ptr) }; - std::mem::forget(result.clone()) + std::mem::forget(result.clone()); result } From b229c45f0ae3e4b67ee1805aac15fa1c629f9b74 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 08:59:44 +0800 Subject: [PATCH 06/13] Update rc.rs --- library/alloc/src/rc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 0b15db911a818..d79ebbf210f45 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -749,7 +749,7 @@ impl Rc { Rc::from_raw(ptr) }; - std::mem::forget(result.clone()); + forget(result.clone()); result } From 6a7a133cddbab4be88482a06de5de1956ec44e0c Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 09:00:20 +0800 Subject: [PATCH 07/13] Update sync.rs --- library/alloc/src/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index da0fddc69c71f..0a4313b987787 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -14,7 +14,7 @@ use core::hint; use core::intrinsics::abort; use core::iter; use core::marker::{PhantomData, Unpin, Unsize}; -use core::mem::{self, align_of_val, size_of_val}; +use core::mem::{self, align_of_val, forget, size_of_val}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -766,7 +766,7 @@ impl Arc { Arc::from_raw(ptr) }; - std::mem::forget(result.clone()); + forget(result.clone()); result } From 72c6685346475e06227fd50483de276f3bc05e52 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 09:09:12 +0800 Subject: [PATCH 08/13] Update sync.rs --- library/alloc/src/sync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 0a4313b987787..426b3188bf934 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -761,6 +761,7 @@ impl Arc { } /// Obtains a new reference to a raw [`Arc`] pointer, without taking ownership. + #[unstable(feature = "rc_clone_raw", issue = "48108")] pub fn clone_raw(ptr: *const T) -> Self { let result = unsafe { Arc::from_raw(ptr) From 934c8588c3c3c83ce8ce7d444376e28aed876713 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sat, 12 Dec 2020 09:10:04 +0800 Subject: [PATCH 09/13] Update rc.rs --- library/alloc/src/rc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index d79ebbf210f45..5292efe073909 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -744,6 +744,7 @@ impl Rc { } /// Obtains a new reference two a raw [`Rc`] pointer, without taking ownership. + #[unstable(feature = "rc_clone_raw", issue = "48108")] pub unsafe fn clone_raw(ptr: *const T) -> Self { let result = unsafe { Rc::from_raw(ptr) From 9d7eae2ca4ec87d1b27dce8b34c6bb68cffe857a Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:13:03 +0800 Subject: [PATCH 10/13] Update rc.rs --- library/alloc/src/rc.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 5292efe073909..d52491098f236 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -743,12 +743,10 @@ impl Rc { unsafe { Self::from_ptr(rc_ptr) } } - /// Obtains a new reference two a raw [`Rc`] pointer, without taking ownership. + /// Obtains a new reference to a raw [`Rc`] pointer, without taking ownership. #[unstable(feature = "rc_clone_raw", issue = "48108")] pub unsafe fn clone_raw(ptr: *const T) -> Self { - let result = unsafe { - Rc::from_raw(ptr) - }; + let result = unsafe { Rc::from_raw(ptr) }; forget(result.clone()); From dc11b87a15a33d8efdbdd0651358552f14541488 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:13:46 +0800 Subject: [PATCH 11/13] Update sync.rs --- library/alloc/src/sync.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 426b3188bf934..ca90dd3919faf 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -763,9 +763,7 @@ impl Arc { /// Obtains a new reference to a raw [`Arc`] pointer, without taking ownership. #[unstable(feature = "rc_clone_raw", issue = "48108")] pub fn clone_raw(ptr: *const T) -> Self { - let result = unsafe { - Arc::from_raw(ptr) - }; + let result = unsafe { Arc::from_raw(ptr) }; forget(result.clone()); From 069b5d1da49ea11178598c1bda9bfb4a3660a4ae Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Mon, 14 Dec 2020 08:05:30 +0800 Subject: [PATCH 12/13] Update sync.rs --- library/alloc/src/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index ca90dd3919faf..eca4588ce435d 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -759,12 +759,12 @@ impl Arc { Self::from_ptr(arc_ptr) } } - + /// Obtains a new reference to a raw [`Arc`] pointer, without taking ownership. #[unstable(feature = "rc_clone_raw", issue = "48108")] pub fn clone_raw(ptr: *const T) -> Self { let result = unsafe { Arc::from_raw(ptr) }; - + forget(result.clone()); result From e7907ff8d322608eb2474285a9b81b77b03bc1e1 Mon Sep 17 00:00:00 2001 From: HTG-YT <39023054+HTG-YT@users.noreply.github.com> Date: Mon, 14 Dec 2020 08:06:15 +0800 Subject: [PATCH 13/13] Update rc.rs --- library/alloc/src/rc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index d52491098f236..0e53fed8d0e99 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -742,14 +742,14 @@ impl Rc { unsafe { Self::from_ptr(rc_ptr) } } - + /// Obtains a new reference to a raw [`Rc`] pointer, without taking ownership. #[unstable(feature = "rc_clone_raw", issue = "48108")] pub unsafe fn clone_raw(ptr: *const T) -> Self { let result = unsafe { Rc::from_raw(ptr) }; - + forget(result.clone()); - + result }