-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guarantee char
layout
#1401
Guarantee char
layout
#1401
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,9 @@ is valid UTF-8. Calling a `str` method with a non-UTF-8 buffer can cause | |
Since `str` is a [dynamically sized type], it can only be instantiated through a | ||
pointer type, such as `&str`. | ||
|
||
## Bit validity | ||
## Layout and bit validity | ||
|
||
`char` is guaranteed to have the same size and alignment as `u32` on all platforms. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I was surprised this was to the reference directly, not to I was going to suggest something like /// ```
/// use std::alloc::Layout;
/// assert_eq!(Layout::new::<char>(), Layout::new::<u32>());
/// assert_eq!(Layout::new::<Option<char>>(), Layout::new::<u32>());
/// ```
but then this wasn't a docs change... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No opposition to this going in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put up a PR to add the same text to |
||
|
||
Every byte of a `char` is guaranteed to be initialized (in other words, | ||
`transmute::<char, [u8; size_of::<char>()]>(...)` is always sound -- but since | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Unless we want to put this somewhere else.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion should probably be handled separately, not in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #1426 to track this.