Skip to content
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a591d7a
Add strong_count mutation methods to Rc
mystor Mar 25, 2021
960b699
Do not emit the advanced diagnostics on macros
JohnTitor Mar 29, 2021
81f00c9
Trigger `unused_doc_comments` on macros at once
JohnTitor Apr 3, 2021
815de0e
Move a `unused_doc_comments ` test to the `unused` dir
JohnTitor Apr 3, 2021
32be124
Use AnonConst for asm! constants
Amanieu Apr 6, 2021
ee79f83
forbid `impl Trait` in generic param defaults
SNCPlay42 Apr 6, 2021
7f823e5
Add reborrow suggestion when mutable reference is moved in a for loop
SkiFire13 Apr 6, 2021
a775984
Add regression test
SkiFire13 Apr 6, 2021
b8dda53
Remove trailing `:` from E0119 message
estebank Apr 7, 2021
18cf44b
Do not ICE when closure is involved in TAIT
estebank Apr 7, 2021
4752a54
Disable using non-ascii identifiers in extern blocks.
crlf0710 Apr 6, 2021
505846e
Rollup merge of #83476 - mystor:rc_mutate_strong_count, r=m-ou-se
Dylan-DPC Apr 7, 2021
2c55bac
Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkor
Dylan-DPC Apr 7, 2021
4d5bb1c
Rollup merge of #83816 - JohnTitor:unused-doc-comments-on-macros, r=v…
Dylan-DPC Apr 7, 2021
b81c6cd
Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkov
Dylan-DPC Apr 7, 2021
d554385
Rollup merge of #83935 - SNCPlay42:param-default-impl-trait, r=varkor
Dylan-DPC Apr 7, 2021
9c688cd
Rollup merge of #83936 - crlf0710:disallow_extern_block_non_ascii, r=…
Dylan-DPC Apr 7, 2021
d7d42cc
Rollup merge of #83945 - SkiFire13:fix-83924, r=estebank
Dylan-DPC Apr 7, 2021
d82419b
Rollup merge of #83954 - estebank:issue-83613, r=varkor
Dylan-DPC Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,73 @@ impl<T: ?Sized> Rc<T> {
this.inner().strong()
}

/// Increments the strong reference count on the `Rc<T>` associated with the
/// provided pointer by one.
///
/// # Safety
///
/// The pointer must have been obtained through `Rc::into_raw`, and the
/// associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) for the duration of this method.
///
/// # Examples
///
/// ```
/// use std::rc::Rc;
///
/// let five = Rc::new(5);
///
/// unsafe {
/// let ptr = Rc::into_raw(five);
/// Rc::increment_strong_count(ptr);
///
/// let five = Rc::from_raw(ptr);
/// assert_eq!(2, Rc::strong_count(&five));
/// }
/// ```
#[inline]
#[stable(feature = "rc_mutate_strong_count", since = "1.53.0")]
pub unsafe fn increment_strong_count(ptr: *const T) {
// Retain Rc, but don't touch refcount by wrapping in ManuallyDrop
let rc = unsafe { mem::ManuallyDrop::new(Rc::<T>::from_raw(ptr)) };
// Now increase refcount, but don't drop new refcount either
let _rc_clone: mem::ManuallyDrop<_> = rc.clone();
}

/// Decrements the strong reference count on the `Rc<T>` associated with the
/// provided pointer by one.
///
/// # Safety
///
/// The pointer must have been obtained through `Rc::into_raw`, and the
/// associated `Rc` instance must be valid (i.e. the strong count must be at
/// least 1) when invoking this method. This method can be used to release
/// the final `Rc` and backing storage, but **should not** be called after
/// the final `Rc` has been released.
///
/// # Examples
///
/// ```
/// use std::rc::Rc;
///
/// let five = Rc::new(5);
///
/// unsafe {
/// let ptr = Rc::into_raw(five);
/// Rc::increment_strong_count(ptr);
///
/// let five = Rc::from_raw(ptr);
/// assert_eq!(2, Rc::strong_count(&five));
/// Rc::decrement_strong_count(ptr);
/// assert_eq!(1, Rc::strong_count(&five));
/// }
/// ```
#[inline]
#[stable(feature = "rc_mutate_strong_count", since = "1.53.0")]
pub unsafe fn decrement_strong_count(ptr: *const T) {
unsafe { mem::drop(Rc::from_raw(ptr)) };
}

/// Returns `true` if there are no other `Rc` or [`Weak`] pointers to
/// this allocation.
#[inline]
Expand Down