Skip to content

Guarantee that raw pointer conversions preserve slice element count #1417

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 7 commits into from
Nov 4, 2023

Conversation

joshlf
Copy link
Contributor

@joshlf joshlf commented Oct 11, 2023

This encodes the behavior agreed upon in rust-lang/unsafe-code-guidelines#288.

@joshlf
Copy link
Contributor Author

joshlf commented Oct 24, 2023

Friendly ping 🙂

@ehuss
Copy link
Contributor

ehuss commented Oct 24, 2023

Nominating for lang, but I'm not sure if they would defer this decision to someone else, like t-opsem. cc @RalfJung

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Substance LGTM, I have a nitpick on the wording.

@nikomatsakis
Copy link
Contributor

@rfcbot fcp merge

We discussed in the @rust-lang/lang meeting today and meeting consensus was to merge this. Documenting that.

@rfcbot
Copy link

rfcbot commented Oct 25, 2023

Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@RalfJung
Copy link
Member

RalfJung commented Oct 25, 2023

This sounds like a lang decision to me, since it's about stable guarantees of how a type works. Still Cc @rust-lang/opsem

@scottmcm
Copy link
Member

scottmcm commented Oct 25, 2023

I think this is often sketchy, and it might overall be better to encourage ptr::slice_from_raw_parts instead of as for this, but regardless this is what it does on stable so 👍 we should have that recorded in the reference.

@rfcbot reviewed

@rfcbot
Copy link

rfcbot commented Oct 25, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

psst @nikomatsakis, I wasn't able to add the final-comment-period label, please do so.

@joshlf
Copy link
Contributor Author

joshlf commented Oct 25, 2023

I think this is often sketchy, and it might overall be better to encourage ptr::slice_from_raw_parts instead of as for this, but regardless this is what it does on stable so 👍 we should have that recorded in the reference.

@rfcbot reviewed

Also worth noting that ptr::slice_from_raw_parts does not work for custom DSTs (eg, struct Foo { u: u8, trailing: [u8] }).

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

This was discussed today and is now in FCP. We'll remove the nomination.

joshlf and others added 2 commits October 25, 2023 21:42
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
@rfcbot
Copy link

rfcbot commented Nov 4, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

psst @nikomatsakis, I wasn't able to add the finished-final-comment-period label, please do so.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

@ehuss ehuss enabled auto-merge November 4, 2023 17:18
@ehuss ehuss added this pull request to the merge queue Nov 4, 2023
Merged via the queue into rust-lang:master with commit cd8193e Nov 4, 2023
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 b0ee9ec..77dbe57
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 b0ee9ec..77dbe57
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)
@joshlf joshlf deleted the patch-3 branch November 11, 2023 22:18
joshlf added a commit to google/zerocopy that referenced this pull request Nov 27, 2023
Since raw pointer slice casts are now guaranteed to preserve element
count [1], we no longer need to separately store the byte length of a
`Ptr`. Instead, we can compute it from the raw pointer field.

[1] rust-lang/reference#1417
joshlf added a commit to google/zerocopy that referenced this pull request Nov 27, 2023
Since raw pointer slice casts are now guaranteed to preserve element
count [1], we no longer need to separately store the byte length of a
`Ptr`. Instead, we can compute it from the raw pointer field.

[1] rust-lang/reference#1417
github-merge-queue bot pushed a commit to google/zerocopy that referenced this pull request Nov 27, 2023
Since raw pointer slice casts are now guaranteed to preserve element
count [1], we no longer need to separately store the byte length of a
`Ptr`. Instead, we can compute it from the raw pointer field.

[1] rust-lang/reference#1417
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.