Skip to content

Support repr alignment on unions. #43274

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

Merged
merged 1 commit into from
Jul 22, 2017
Merged

Conversation

bitshifter
Copy link
Contributor

Requested as part of RFC 1358 #33626 (comment).

@rust-highfive
Copy link
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)


#![feature(attr_literals)]
#![feature(repr_align)]
#![feature(untagged_unions)]
Copy link
Contributor

Choose a reason for hiding this comment

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

The feature should be unnecessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried removing it, but it seems it's still needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked more into why this is the case - it's needed because of the struct inside the union in one of the tests. The struct is not Copy by default and unions require their members to be copy by default. Non-copy types in untagged unions aren't stabilised yet. If I made the struct derive from Copy then I could probably remove the feature, I think I'll leave it for now though.

@@ -176,6 +182,18 @@ pub fn main() {
}
assert!(is_aligned_to(&e, 16));

// check union alignment
assert_eq!(mem::align_of::<UnionContainsAlign>(), 16);
assert_eq!(mem::size_of::<UnionContainsAlign>(), 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should it be 32? It's a union, not a struct, the size should be the same as the largest element shouldn't it?


fn main() {
assert_eq!(align_of::<U16>(), 16);
assert_eq!(size_of::<U16>(), 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment as above, size of should be max(union stride, a string and b stride) shouldn't it?

@petrochenkov
Copy link
Contributor

petrochenkov commented Jul 17, 2017

Disregard everything I wrote, it's 3 A.M. and I'm mixing bits and bytes. :shame:

@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 17, 2017
@arielb1
Copy link
Contributor

arielb1 commented Jul 18, 2017

r? @petrochenkov

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 21, 2017

📌 Commit ebc2f7d has been approved by petrochenkov

@bors
Copy link
Collaborator

bors commented Jul 21, 2017

⌛ Testing commit ebc2f7d with merge 504328a...

bors added a commit that referenced this pull request Jul 21, 2017
Support repr alignment on unions.

Requested as part of RFC 1358 #33626 (comment).
@bors
Copy link
Collaborator

bors commented Jul 22, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 504328a to master...

@bors bors merged commit ebc2f7d into rust-lang:master Jul 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants