@@ -1186,8 +1186,8 @@ impl<T: ?Sized> Rc<T> {
11861186 /// * If `U` is sized, it must have the same size and alignment as `T`. This
11871187 /// is trivially true if `U` is `T`.
11881188 /// * If `U` is unsized, its data pointer must have the same size and
1189- /// alignment as `T`. This is trivially true if `Arc <U>` was constructed
1190- /// through `Arc <T>` and then converted to `Arc <U>` through an [unsized
1189+ /// alignment as `T`. This is trivially true if `Rc <U>` was constructed
1190+ /// through `Rc <T>` and then converted to `Rc <U>` through an [unsized
11911191 /// coercion].
11921192 ///
11931193 /// Note that if `U` or `U`'s data pointer is not `T` but has the same size
@@ -1363,13 +1363,20 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13631363
13641364 /// Constructs an `Rc<T, A>` from a raw pointer in the provided allocator.
13651365 ///
1366- /// The raw pointer must have been previously returned by a call to
1367- /// [`Rc<U, A>::into_raw`][into_raw] where `U` must have the same size
1368- /// and alignment as `T`. This is trivially true if `U` is `T`.
1369- /// Note that if `U` is not `T` but has the same size and alignment, this is
1370- /// basically like transmuting references of different types. See
1371- /// [`mem::transmute`] for more information on what
1372- /// restrictions apply in this case.
1366+ /// The raw pointer must have been previously returned by a call to [`Rc<U,
1367+ /// A>::into_raw`][into_raw] with the following requirements:
1368+ ///
1369+ /// * If `U` is sized, it must have the same size and alignment as `T`. This
1370+ /// is trivially true if `U` is `T`.
1371+ /// * If `U` is unsized, its data pointer must have the same size and
1372+ /// alignment as `T`. This is trivially true if `Rc<U>` was constructed
1373+ /// through `Rc<T>` and then converted to `Rc<U>` through an [unsized
1374+ /// coercion].
1375+ ///
1376+ /// Note that if `U` or `U`'s data pointer is not `T` but has the same size
1377+ /// and alignment, this is basically like transmuting references of
1378+ /// different types. See [`mem::transmute`][transmute] for more information
1379+ /// on what restrictions apply in this case.
13731380 ///
13741381 /// The raw pointer must point to a block of memory allocated by `alloc`
13751382 ///
@@ -1380,6 +1387,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13801387 /// even if the returned `Rc<T>` is never accessed.
13811388 ///
13821389 /// [into_raw]: Rc::into_raw
1390+ /// [unsized coercion]: https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
13831391 ///
13841392 /// # Examples
13851393 ///
@@ -1402,6 +1410,23 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
14021410 ///
14031411 /// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
14041412 /// ```
1413+ ///
1414+ /// Convert a slice back into its original array:
1415+ ///
1416+ /// ```
1417+ /// #![feature(allocator_api)]
1418+ ///
1419+ /// use std::rc::Rc;
1420+ /// use std::alloc::System;
1421+ ///
1422+ /// let x: Rc<[u32]> = Rc::new_in([1, 2, 3], System);
1423+ /// let x_ptr: *const [u32] = Rc::into_raw(x);
1424+ ///
1425+ /// unsafe {
1426+ /// let x: Rc<[u32; 3]> = Rc::from_raw_in(x_ptr.cast::<[u32; 3]>(), System);
1427+ /// assert_eq!(&*x, &[1, 2, 3]);
1428+ /// }
1429+ /// ```
14051430 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
14061431 pub unsafe fn from_raw_in ( ptr : * const T , alloc : A ) -> Self {
14071432 let offset = unsafe { data_offset ( ptr) } ;
0 commit comments