Skip to content

Commit

Permalink
Rollup merge of rust-lang#77836 - RalfJung:transmute_copy, r=Mark-Sim…
Browse files Browse the repository at this point in the history
…ulacrum

transmute_copy: explain that alignment is handled correctly

The doc comment currently is somewhat misleading because if it actually transmuted `&T` to `&U`, a higher-aligned `U` would be problematic.
  • Loading branch information
Dylan-DPC authored Oct 26, 2020
2 parents 34d2351 + 95aac44 commit 46f9f01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,10 @@ pub fn drop<T>(_x: T) {}
/// Interprets `src` as having type `&U`, and then reads `src` without moving
/// the contained value.
///
/// This function will unsafely assume the pointer `src` is valid for
/// [`size_of::<U>`][size_of] bytes by transmuting `&T` to `&U` and then reading
/// the `&U`. It will also unsafely create a copy of the contained value instead of
/// moving out of `src`.
/// This function will unsafely assume the pointer `src` is valid for [`size_of::<U>`][size_of]
/// bytes by transmuting `&T` to `&U` and then reading the `&U` (except that this is done in a way
/// that is correct even when `&U` makes stricter alignment requirements than `&T`). It will also
/// unsafely create a copy of the contained value instead of moving out of `src`.
///
/// It is not a compile-time error if `T` and `U` have different sizes, but it
/// is highly encouraged to only invoke this function where `T` and `U` have the
Expand Down

0 comments on commit 46f9f01

Please sign in to comment.