Skip to content

Commit

Permalink
Rollup merge of rust-lang#44536 - Havvy:transmute-docs, r=steveklabnik
Browse files Browse the repository at this point in the history
Fix example in transmute; add safety requirement to Vec::from_raw_parts

This fixes the second bullet point on rust-lang#44281 and also removes some incorrect information.
  • Loading branch information
GuillaumeGomez authored Sep 13, 2017
2 parents 0aade70 + 9dd2ee1 commit 5d9e3ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl<T> Vec<T> {
///
/// * `ptr` needs to have been previously allocated via [`String`]/`Vec<T>`
/// (at least, it's highly likely to be incorrect if it wasn't).
/// * `ptr`'s `T` needs to have the same size and alignment as it was allocated with.
/// * `length` needs to be less than or equal to `capacity`.
/// * `capacity` needs to be the capacity that the pointer was allocated with.
///
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,12 @@ extern "rust-intrinsic" {
/// // The no-copy, unsafe way, still using transmute, but not UB.
/// // This is equivalent to the original, but safer, and reuses the
/// // same Vec internals. Therefore the new inner type must have the
/// // exact same size, and the same or lesser alignment, as the old
/// // type. The same caveats exist for this method as transmute, for
/// // exact same size, and the same alignment, as the old type.
/// // The same caveats exist for this method as transmute, for
/// // the original inner type (`&i32`) to the converted inner type
/// // (`Option<&i32>`), so read the nomicon pages linked above.
/// let v_from_raw = unsafe {
/// Vec::from_raw_parts(v_orig.as_mut_ptr(),
/// Vec::from_raw_parts(v_orig.as_mut_ptr() as *mut Option<&i32>,
/// v_orig.len(),
/// v_orig.capacity())
/// };
Expand Down

0 comments on commit 5d9e3ef

Please sign in to comment.