Skip to content

Commit 57e0dea

Browse files
committed
Document requirements for unsized {Rc,Arc}::from_raw
1 parent 6351247 commit 57e0dea

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

library/alloc/src/rc.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1181,12 +1181,19 @@ impl<T: ?Sized> Rc<T> {
11811181
/// Constructs an `Rc<T>` from a raw pointer.
11821182
///
11831183
/// The raw pointer must have been previously returned by a call to
1184-
/// [`Rc<U>::into_raw`][into_raw] where `U` must have the same size
1185-
/// and alignment as `T`. This is trivially true if `U` is `T`.
1186-
/// Note that if `U` is not `T` but has the same size and alignment, this is
1187-
/// basically like transmuting references of different types. See
1188-
/// [`mem::transmute`][transmute] for more information on what
1189-
/// restrictions apply in this case.
1184+
/// [`Rc<U>::into_raw`][into_raw] with the following requirements:
1185+
///
1186+
/// * If `U` is sized, it must have the same size and alignment as `T`. This
1187+
/// is trivially true if `U` is `T`.
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
1191+
/// coercion].
1192+
///
1193+
/// Note that if `U` or `U`'s data pointer is not `T` but has the same size
1194+
/// and alignment, this is basically like transmuting references of
1195+
/// different types. See [`mem::transmute`][transmute] for more information
1196+
/// on what restrictions apply in this case.
11901197
///
11911198
/// The raw pointer must point to a block of memory allocated by the global allocator
11921199
///
@@ -1198,6 +1205,7 @@ impl<T: ?Sized> Rc<T> {
11981205
///
11991206
/// [into_raw]: Rc::into_raw
12001207
/// [transmute]: core::mem::transmute
1208+
/// [unsized coercion]: https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
12011209
///
12021210
/// # Examples
12031211
///

library/alloc/src/sync.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1329,12 +1329,19 @@ impl<T: ?Sized> Arc<T> {
13291329
/// Constructs an `Arc<T>` from a raw pointer.
13301330
///
13311331
/// The raw pointer must have been previously returned by a call to
1332-
/// [`Arc<U>::into_raw`][into_raw] where `U` must have the same size and
1333-
/// alignment as `T`. This is trivially true if `U` is `T`.
1334-
/// Note that if `U` is not `T` but has the same size and alignment, this is
1335-
/// basically like transmuting references of different types. See
1336-
/// [`mem::transmute`][transmute] for more information on what
1337-
/// restrictions apply in this case.
1332+
/// [`Arc<U>::into_raw`][into_raw] with the following requirements:
1333+
///
1334+
/// * If `U` is sized, it must have the same size and alignment as `T`. This
1335+
/// is trivially true if `U` is `T`.
1336+
/// * If `U` is unsized, its data pointer must have the same size and
1337+
/// alignment as `T`. This is trivially true if `Arc<U>` was constructed
1338+
/// through `Arc<T>` and then converted to `Arc<U>` through an [unsized
1339+
/// coercion].
1340+
///
1341+
/// Note that if `U` or `U`'s data pointer is not `T` but has the same size
1342+
/// and alignment, this is basically like transmuting references of
1343+
/// different types. See [`mem::transmute`][transmute] for more information
1344+
/// on what restrictions apply in this case.
13381345
///
13391346
/// The user of `from_raw` has to make sure a specific value of `T` is only
13401347
/// dropped once.
@@ -1344,6 +1351,7 @@ impl<T: ?Sized> Arc<T> {
13441351
///
13451352
/// [into_raw]: Arc::into_raw
13461353
/// [transmute]: core::mem::transmute
1354+
/// [unsized coercion]: https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
13471355
///
13481356
/// # Examples
13491357
///

0 commit comments

Comments
 (0)