@@ -881,7 +881,8 @@ extern "rust-intrinsic" {
881
881
/// // clone the vector as we will reuse them later
882
882
/// let v_clone = v_orig.clone();
883
883
///
884
- /// // Using transmute: this is Undefined Behavior, and a bad idea.
884
+ /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
885
+ /// // bad idea and could cause Undefined Behavior.
885
886
/// // However, it is no-copy.
886
887
/// let v_transmuted = unsafe {
887
888
/// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
@@ -897,13 +898,14 @@ extern "rust-intrinsic" {
897
898
///
898
899
/// let v_clone = v_orig.clone();
899
900
///
900
- /// // The no-copy, unsafe way, still using transmute, but not UB .
901
- /// // This is equivalent to the original, but safer, and reuses the
902
- /// // same `Vec` internals. Therefore, the new inner type must have the
903
- /// // exact same size, and the same alignment, as the old type.
901
+ /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout .
902
+ /// // Like the first approach, this reuses the `Vec` internals.
903
+ /// // Therefore, the new inner type must have the
904
+ /// // exact same size, * and the same alignment* , as the old type.
904
905
/// // The same caveats exist for this method as transmute, for
905
906
/// // the original inner type (`&i32`) to the converted inner type
906
- /// // (`Option<&i32>`), so read the nomicon pages linked above.
907
+ /// // (`Option<&i32>`), so read the nomicon pages linked above and also
908
+ /// // consult the [`from_raw_parts`] documentation.
907
909
/// let v_from_raw = unsafe {
908
910
// FIXME Update this when vec_into_raw_parts is stabilized
909
911
/// // Ensure the original vector is not dropped.
@@ -914,6 +916,8 @@ extern "rust-intrinsic" {
914
916
/// };
915
917
/// ```
916
918
///
919
+ /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
920
+ ///
917
921
/// Implementing `split_at_mut`:
918
922
///
919
923
/// ```
0 commit comments