Skip to content

Conversation

jswrenn
Copy link
Member

@jswrenn jswrenn commented Nov 4, 2024

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.

This looks good, I'm pruning out some of the "team asks" because I think you don't need them actually.

Comment on lines +71 to +72
3. **Safe Usage is Usually Safe**
Uses of `unsafe` fields which cannot violate their invariants *should not* require an unsafe block.
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean, in practice?

Copy link
Member Author

Choose a reason for hiding this comment

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

For example: Using offset_of has no impact on the safety invariants of its given field. Requiring unsafe { ... } to compute the offset of an unsafe field would be pure noise in an unsafe code review, and, as such, we should make an effort to not require unsafe { ... } in this case.

Unlike the first and second tenet, this tenet is a soft requirement. We shouldn't ignore it entirely in our design work, but we don't actually have to implement any of these safe carve-outs initially since it's forwards-compatible to make an unsafe operation safe (so long as doing so doesn't violate existing safety conditions).

@nikomatsakis nikomatsakis merged commit 45b6de0 into rust-lang:main Dec 4, 2024
1 check passed
nikomatsakis added a commit to nikomatsakis/rust-project-goals-ndm that referenced this pull request Jun 5, 2025
Propose "unsafe fields" as a 2025H1 Project Goal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants