@@ -1186,8 +1186,8 @@ impl<T: ?Sized> Rc<T> {
1186
1186
/// * If `U` is sized, it must have the same size and alignment as `T`. This
1187
1187
/// is trivially true if `U` is `T`.
1188
1188
/// * 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
1191
1191
/// coercion].
1192
1192
///
1193
1193
/// 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> {
1363
1363
1364
1364
/// Constructs an `Rc<T, A>` from a raw pointer in the provided allocator.
1365
1365
///
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.
1373
1380
///
1374
1381
/// The raw pointer must point to a block of memory allocated by `alloc`
1375
1382
///
@@ -1380,6 +1387,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1380
1387
/// even if the returned `Rc<T>` is never accessed.
1381
1388
///
1382
1389
/// [into_raw]: Rc::into_raw
1390
+ /// [unsized coercion]: https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
1383
1391
///
1384
1392
/// # Examples
1385
1393
///
@@ -1402,6 +1410,23 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1402
1410
///
1403
1411
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
1404
1412
/// ```
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
+ /// ```
1405
1430
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1406
1431
pub unsafe fn from_raw_in ( ptr : * const T , alloc : A ) -> Self {
1407
1432
let offset = unsafe { data_offset ( ptr) } ;
0 commit comments