Skip to content

Update behavior-considered-undefined.md #1476

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/behavior-considered-undefined.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ omitted in surface Rust syntax due to automatic dereferencing; we are
considering the fully expanded place expression here.)

For instance, if `ptr` has type `*const S` where `S` has an alignment of 8, then
`ptr` must be 8-aligned or else `(*ptr).f` is "based on an misaligned pointer".
`*ptr` must be 8-aligned or else `(*ptr).f` is "based on an misaligned pointer".
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`*ptr` must be 8-aligned or else `(*ptr).f` is "based on an misaligned pointer".
the address contained in `ptr` must be cleanly divisible by 8 or else `(*ptr).f` is "based on an misaligned pointer".

On the rustdocs call today we spent a lot of time trying to determine whether or not this was correct or an improvement. Maybe there's a better way to say this more explicitly that relies less on notation?

The ambiguity all comes from whether we're talking about where the pointer is stored or whether we're talking about the address contained in the pointer.

This is true even if the type of the field `f` is `u8` (i.e., a type with
alignment 1). In other words, the alignment requirement derives from the type of
the pointer that was dereferenced, *not* the type of the field that is being
Expand Down