-
Notifications
You must be signed in to change notification settings - Fork 13.6k
E0793: Clarify that it applies to unions as well #144944
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
base: master
Are you sure you want to change the base?
Conversation
Failed to set assignee to
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Some nits, and can you squash commits please
aligned. `addr_of!` and raw pointers should be used the same way as is done | ||
for `struct` fields. |
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.
aligned. `addr_of!` and raw pointers should be used the same way as is done | |
for `struct` fields. | |
aligned. Use `addr_of!` and raw pointers in the same way as for struct fields. |
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.
Which version should I use?
Use addr_of!
and raw pointers in the same way as for struct fields.
or
addr_of!
and raw pointers should be used in the same way as for struct fields.
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.
I'd stick with first one because it is more direct and imperative
This comment has been minimized.
This comment has been minimized.
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.
Some suggestions. :)
@@ -1,4 +1,4 @@ | |||
An unaligned reference to a field of a [packed] struct got created. | |||
An unaligned reference to a field of a [packed] `struct` or `union` was created. |
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.
A reference was created to an unaligned field of a [packed] `struct` or `union`.
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.
We could also add some futher explanation, for example,
The `#[repr(packed)]` attribute removes padding between fields, which can
cause fields to be stored at unaligned memory addresses. Creating references
to such fields violates Rust's memory safety guarantees and can lead to
undefined behavior in optimized code.
pick up inactive PR: #131472
Also:
Adjust the language slightly to be more consistent with other similar messages (was created instead of got created).
Add a short section on union.
Add an example line showing referencing a field in a packed struct is safe if the field's type isn't more strictly aligned than the pack.
r? compiler-errors