Skip to content
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

Merged
merged 1 commit into from
Oct 30, 2023
Merged

Guarantee char layout #1401

merged 1 commit into from
Oct 30, 2023

Conversation

joshlf
Copy link
Contributor

@joshlf joshlf commented Sep 11, 2023

No description provided.

@joshlf
Copy link
Contributor Author

joshlf commented Oct 16, 2023

Ping 🙂

@ehuss
Copy link
Contributor

ehuss commented Oct 17, 2023

Nominated to get lang's attention.

## Bit validity
## Layout and bit validity

`char` is guaranteed to have the same size and alignment as `u32` on all platforms.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`char` is guaranteed to have the same size and alignment as `u32` on all platforms.
`char` is guaranteed to have the same size and alignment as `u32` on all platforms.
`Option<char>` is guaranteed to have the same size and alignment as `char` on all platforms.

(Unless we want to put this somewhere else.)

Copy link
Member

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.

Copy link
Contributor Author

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.

@joshtriplett
Copy link
Member

Consensus from lang is to merge.

std docs should also be updated.

## Bit validity
## Layout and bit validity

`char` is guaranteed to have the same size and alignment as `u32` on all platforms.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I was surprised this was to the reference directly, not to core like the other guarantees have been done. We currently have no guarantees written for specific alignment of anything, as far as I could find.

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...

Copy link
Contributor Author

@joshlf joshlf Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No opposition to this going in core as well of course, but we already have text in the Reference about the sizes of primitive types: https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put up a PR to add the same text to core: rust-lang/rust#116894

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

@ehuss ehuss added this pull request to the merge queue Oct 30, 2023
Merged via the queue into rust-lang:master with commit 8947db0 Oct 30, 2023
1 check passed
@joshlf joshlf deleted the patch-2 branch October 30, 2023 19:15
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 7, 2023
Update books

## rust-lang/reference

4 commits in 16fd3c06d9e558dae2d52000818274ae70c9e90a..cd8193e972f61b92117095fc73b67af767b4d6bc
2023-11-04 17:19:39 UTC to 2023-10-30 16:04:52 UTC

- Guarantee that raw pointer conversions preserve slice element count (rust-lang/reference#1417)
- some asm block flags also mean there can be no fences (rust-lang/reference#1413)
- Guarantee `char` layout (rust-lang/reference#1401)
- Doc: Add the RISC-V stabilized target features (rust-lang/reference#1415)

## rust-lang/rust-by-example

3 commits in 6709beeb7d0fbc5ffc91ac4893a24434123b9bfa..311b84962016b28c75525c86e7b3f49fd9101a39
2023-10-31 18:32:09 UTC to 2023-10-31 18:30:39 UTC

- Fixed explanation mistake in comment (rust-lang/rust-by-example#1761)
- Fix typos (rust-lang/rust-by-example#1759)
- docs(9.2): fix typo (rust-lang/rust-by-example#1754)

## rust-lang/rustc-dev-guide

6 commits in b0ee9ec8fa59a6c7620165e061f4747202377a62..77dbe5782b2488af3bb489ad702eaff438f465bf
2023-11-06 16:14:34 UTC to 2023-10-29 17:16:02 UTC

- add a new type system invariant (rust-lang/rustc-dev-guide#1822)
- Update some outdated descriptions of coverage instrumentation (rust-lang/rustc-dev-guide#1809)
- Add some documentation for unsizing (rust-lang/rustc-dev-guide#1817)
- Bibliography: fixing author of "You Can't Spell Trust Without Rust" (rust-lang/rustc-dev-guide#1815)
- remove change-id from sample build configuration (rust-lang/rustc-dev-guide#1813)
- Update name of "active" features to "unstable" (rust-lang/rustc-dev-guide#1814)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2023
Rollup merge of rust-lang#117639 - rustbot:docs-update, r=ehuss

Update books

## rust-lang/reference

4 commits in 16fd3c06d9e558dae2d52000818274ae70c9e90a..cd8193e972f61b92117095fc73b67af767b4d6bc
2023-11-04 17:19:39 UTC to 2023-10-30 16:04:52 UTC

- Guarantee that raw pointer conversions preserve slice element count (rust-lang/reference#1417)
- some asm block flags also mean there can be no fences (rust-lang/reference#1413)
- Guarantee `char` layout (rust-lang/reference#1401)
- Doc: Add the RISC-V stabilized target features (rust-lang/reference#1415)

## rust-lang/rust-by-example

3 commits in 6709beeb7d0fbc5ffc91ac4893a24434123b9bfa..311b84962016b28c75525c86e7b3f49fd9101a39
2023-10-31 18:32:09 UTC to 2023-10-31 18:30:39 UTC

- Fixed explanation mistake in comment (rust-lang/rust-by-example#1761)
- Fix typos (rust-lang/rust-by-example#1759)
- docs(9.2): fix typo (rust-lang/rust-by-example#1754)

## rust-lang/rustc-dev-guide

6 commits in b0ee9ec8fa59a6c7620165e061f4747202377a62..77dbe5782b2488af3bb489ad702eaff438f465bf
2023-11-06 16:14:34 UTC to 2023-10-29 17:16:02 UTC

- add a new type system invariant (rust-lang/rustc-dev-guide#1822)
- Update some outdated descriptions of coverage instrumentation (rust-lang/rustc-dev-guide#1809)
- Add some documentation for unsizing (rust-lang/rustc-dev-guide#1817)
- Bibliography: fixing author of "You Can't Spell Trust Without Rust" (rust-lang/rustc-dev-guide#1815)
- remove change-id from sample build configuration (rust-lang/rustc-dev-guide#1813)
- Update name of "active" features to "unstable" (rust-lang/rustc-dev-guide#1814)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment