Skip to content

Commit 8abff9b

Browse files
committed
Merge from rustc
2 parents 488d048 + b26ef3d commit 8abff9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1285
-246
lines changed

alloc/src/boxed/thin.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ unsafe impl<T: ?Sized + Sync> Sync for ThinBox<T> {}
4848

4949
#[unstable(feature = "thin_box", issue = "92791")]
5050
impl<T> ThinBox<T> {
51-
/// Moves a type to the heap with its `Metadata` stored in the heap allocation instead of on
51+
/// Moves a type to the heap with its [`Metadata`] stored in the heap allocation instead of on
5252
/// the stack.
5353
///
5454
/// # Examples
@@ -59,6 +59,8 @@ impl<T> ThinBox<T> {
5959
///
6060
/// let five = ThinBox::new(5);
6161
/// ```
62+
///
63+
/// [`Metadata`]: core::ptr::Pointee::Metadata
6264
#[cfg(not(no_global_oom_handling))]
6365
pub fn new(value: T) -> Self {
6466
let meta = ptr::metadata(&value);
@@ -69,7 +71,7 @@ impl<T> ThinBox<T> {
6971

7072
#[unstable(feature = "thin_box", issue = "92791")]
7173
impl<Dyn: ?Sized> ThinBox<Dyn> {
72-
/// Moves a type to the heap with its `Metadata` stored in the heap allocation instead of on
74+
/// Moves a type to the heap with its [`Metadata`] stored in the heap allocation instead of on
7375
/// the stack.
7476
///
7577
/// # Examples
@@ -80,6 +82,8 @@ impl<Dyn: ?Sized> ThinBox<Dyn> {
8082
///
8183
/// let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);
8284
/// ```
85+
///
86+
/// [`Metadata`]: core::ptr::Pointee::Metadata
8387
#[cfg(not(no_global_oom_handling))]
8488
pub fn new_unsize<T>(value: T) -> Self
8589
where

alloc/src/collections/btree/borrow.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ impl<'a, T> DormantMutRef<'a, T> {
4141
// SAFETY: our own safety conditions imply this reference is again unique.
4242
unsafe { &mut *self.ptr.as_ptr() }
4343
}
44+
45+
/// Borrows a new mutable reference from the unique borrow initially captured.
46+
///
47+
/// # Safety
48+
///
49+
/// The reborrow must have ended, i.e., the reference returned by `new` and
50+
/// all pointers and references derived from it, must not be used anymore.
51+
pub unsafe fn reborrow(&mut self) -> &'a mut T {
52+
// SAFETY: our own safety conditions imply this reference is again unique.
53+
unsafe { &mut *self.ptr.as_ptr() }
54+
}
55+
56+
/// Borrows a new shared reference from the unique borrow initially captured.
57+
///
58+
/// # Safety
59+
///
60+
/// The reborrow must have ended, i.e., the reference returned by `new` and
61+
/// all pointers and references derived from it, must not be used anymore.
62+
pub unsafe fn reborrow_shared(&self) -> &'a T {
63+
// SAFETY: our own safety conditions imply this reference is again unique.
64+
unsafe { &*self.ptr.as_ptr() }
65+
}
4466
}
4567

4668
#[cfg(test)]

0 commit comments

Comments
 (0)