File tree 2 files changed +26
-10
lines changed
2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -570,16 +570,24 @@ impl<T: ?Sized> Rc<T> {
570
570
ptr
571
571
}
572
572
573
- /// Constructs an `Rc` from a raw pointer.
573
+ /// Constructs an `Rc<T> ` from a raw pointer.
574
574
///
575
- /// The raw pointer must have been previously returned by a call to a
576
- /// [`Rc::into_raw`][into_raw] using the same `T`.
575
+ /// The raw pointer must have been previously returned by a call to
576
+ /// [`Rc<U>::into_raw`][into_raw] where `U` must have the same size
577
+ /// and alignment as `T`. This is trivially true if `U` is `T`.
578
+ /// Note that if `U` is not `T` but has the same size and alignment, this is
579
+ /// basically like transmuting references of different types. See
580
+ /// [`mem::transmute`][transmute] for more information on what
581
+ /// restrictions apply in this case.
582
+ ///
583
+ /// The user of `from_raw` has to make sure a specific value of `T` is only
584
+ /// dropped once.
577
585
///
578
586
/// This function is unsafe because improper use may lead to memory unsafety,
579
- /// even if `T` is never accessed. For example, a double-free may occur if the function is
580
- /// called twice on the same raw pointer.
587
+ /// even if the returned `Rc<T>` is never accessed.
581
588
///
582
589
/// [into_raw]: struct.Rc.html#method.into_raw
590
+ /// [transmute]: ../../std/mem/fn.transmute.html
583
591
///
584
592
/// # Examples
585
593
///
Original file line number Diff line number Diff line change @@ -550,16 +550,24 @@ impl<T: ?Sized> Arc<T> {
550
550
ptr
551
551
}
552
552
553
- /// Constructs an `Arc` from a raw pointer.
553
+ /// Constructs an `Arc<T> ` from a raw pointer.
554
554
///
555
- /// The raw pointer must have been previously returned by a call to a
556
- /// [`Arc::into_raw`][into_raw], using the same `T`.
555
+ /// The raw pointer must have been previously returned by a call to
556
+ /// [`Arc<U>::into_raw`][into_raw] where `U` must have the same size and
557
+ /// alignment as `T`. This is trivially true if `U` is `T`.
558
+ /// Note that if `U` is not `T` but has the same size and alignment, this is
559
+ /// basically like transmuting references of different types. See
560
+ /// [`mem::transmute`][transmute] for more information on what
561
+ /// restrictions apply in this case.
562
+ ///
563
+ /// The user of `from_raw` has to make sure a specific value of `T` is only
564
+ /// dropped once.
557
565
///
558
566
/// This function is unsafe because improper use may lead to memory unsafety,
559
- /// even if `T` is never accessed. For example, a double-free may occur if the function is
560
- /// called twice on the same raw pointer.
567
+ /// even if the returned `Arc<T>` is never accessed.
561
568
///
562
569
/// [into_raw]: struct.Arc.html#method.into_raw
570
+ /// [transmute]: ../../std/mem/fn.transmute.html
563
571
///
564
572
/// # Examples
565
573
///
You can’t perform that action at this time.
0 commit comments