Rollup merge of #116894 - joshlf:patch-12, r=RalfJung

Guarantee that `char` has the same size and alignment as `u32`
This commit is contained in:
Matthias Krüger 2023-11-04 21:38:28 +01:00 committed by GitHub
commit 805a56fc28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -283,7 +283,7 @@ mod prim_never {}
/// `char` type. For technical reasons, there is additional, separate /// `char` type. For technical reasons, there is additional, separate
/// documentation in [the `std::char` module](char/index.html) as well. /// documentation in [the `std::char` module](char/index.html) as well.
/// ///
/// # Validity /// # Validity and Layout
/// ///
/// A `char` is a '[Unicode scalar value]', which is any '[Unicode code point]' /// A `char` is a '[Unicode scalar value]', which is any '[Unicode code point]'
/// other than a [surrogate code point]. This has a fixed numerical definition: /// other than a [surrogate code point]. This has a fixed numerical definition:
@ -330,6 +330,13 @@ mod prim_never {}
/// ("noncharacters"); and some may be given different meanings by different /// ("noncharacters"); and some may be given different meanings by different
/// users ("private use"). /// users ("private use").
/// ///
/// `char` is guaranteed to have the same size and alignment as `u32` on all
/// platforms.
/// ```
/// use std::alloc::Layout;
/// assert_eq!(Layout::new::<char>(), Layout::new::<u32>());
/// ```
///
/// [Unicode code point]: https://www.unicode.org/glossary/#code_point /// [Unicode code point]: https://www.unicode.org/glossary/#code_point
/// [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value /// [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value
/// [non-exhaustive match]: ../book/ch06-02-match.html#matches-are-exhaustive /// [non-exhaustive match]: ../book/ch06-02-match.html#matches-are-exhaustive