Rollup merge of #42252 - stjepang:clarify-alignof-docs, r=nikomatsakis

Clarify the docs for align_of and its variants

It's okay to have unaligned raw pointers and then use `ptr::write_unaligned` and `ptr::read_unaligned`.
However, using unaligned `&T` and `&mut T` would be undefined behavior.

The current documentation seems to indicate that everything has to be aligned, but in reality only references do. This PR changes the text of docs accordingly.

r? @sfackler
This commit is contained in:
Mark Simulacrum 2017-05-31 10:52:46 -06:00 committed by GitHub
commit c0df1d4e80

View file

@ -220,7 +220,7 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
/// Returns the [ABI]-required minimum alignment of a type.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
///
@ -243,7 +243,7 @@ pub fn min_align_of<T>() -> usize {
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
///
@ -264,7 +264,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
/// Returns the [ABI]-required minimum alignment of a type.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
///
@ -285,7 +285,7 @@ pub fn align_of<T>() -> usize {
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
///