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

E0793: Clarify that it applies to unions as well #131472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kupiakos
Copy link
Contributor

@kupiakos kupiakos commented Oct 9, 2024

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.

This might need to wait for #131456 to merge first? Not sure.

r? compiler-errors

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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2024
@bors
Copy link
Contributor

bors commented Oct 10, 2024

☔ The latest upstream changes (presumably #131458) made this pull request unmergeable. Please resolve the merge conflicts.

let foo = Foo { field1: 0 };
// Accessing the field directly is fine.
let val = foo.field1;
// A reference to a packed union field causes a error.
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
// A reference to a packed union field causes a error.
// A reference to a packed union field causes an error.

Comment on lines +74 to +77
// Accessing the field directly is fine.
let val = foo.field1;
// A reference to a packed union field causes a error.
let val = &foo.field1; // ERROR
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
// Accessing the field directly is fine.
let val = foo.field1;
// A reference to a packed union field causes a error.
let val = &foo.field1; // ERROR
// Accessing the field directly is fine.
let val = foo.field1;
// A reference to a packed union field causes a error.
let val = &foo.field1; // ERROR

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants