Skip to content

New rule layout.repr.c.struct.align-empty#2264

Open
DanielEScherzer wants to merge 1 commit intorust-lang:masterfrom
DanielEScherzer:repr-c-no-fields
Open

New rule layout.repr.c.struct.align-empty#2264
DanielEScherzer wants to merge 1 commit intorust-lang:masterfrom
DanielEScherzer:repr-c-no-fields

Conversation

@DanielEScherzer
Copy link
Copy Markdown
Contributor

No description provided.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 5, 2026
@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. I-lang-easy-decision The decision needed by lang is conjectured to be easy; this dose not imply nomination. labels May 5, 2026
Comment thread src/type-layout.md
The alignment of the struct is the alignment of the most-aligned field in it.

r[layout.repr.c.struct.align-empty]
The alignment of a struct with no fields is 1.
Copy link
Copy Markdown
Member

@RalfJung RalfJung May 6, 2026

Choose a reason for hiding this comment

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

We are moving towards repr(C) being defined entirely by the platform ABI (rust-lang/rfcs#3845). So I'm not sure we should add any such promises.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We talked about this in today's @rust-lang/lang call. Our understanding of the migration plan is that that we'll be adding a today's-edition name for repr(C) (whatever that ends up being named), adding repr(ordered_fields) which will be the same (but indicates that the user explicitly wants that rather than being auto-migrated), and then adding a new repr(C) for the new edition.

Given that transition plan, our understanding is that all the current documentation of repr(C) will move to be documentation of the today's-edition repr(C) and repr(ordered_fields), and then we'll add new documentation for the new repr(C) that largely says we do whatever the platform C ABI does.

Given that transition plan, do you see an issue with this proposal as ongoing documentation of what will end up being the old repr(C) rather than the new one, assuming that all this documentation moves to being for the old one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For what might eventually be called repr(ordered_fields), this new clause is indeed correct.

It's also redundant though, it follows from the definition of the layout algorithm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This rule was proposed in the context of discussing #2243 on the t-lang-docs call yesterday where it was concluded that it does not actually follow from the definition of the layout algorithm - the size and offsets algorithm doesn't describe how to identify the alignment of the type, and the layout.repr.c.struct.align rule says

The alignment of the struct is the alignment of the most-aligned field in it.

but if there are no fields then there is no most-aligned field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Our understanding of the migration plan is that that we'll be adding a today's-edition name for repr(C) (whatever that ends up being named), adding repr(ordered_fields) which will be the same

FWIW, I don't think that end state is set in stone. E.g. to resolve rust-lang/rust#112480, we might potentially end up at a state where all 3 of old repr(C), new repr(C), and repr(ordered_fields) are different.

@traviscross traviscross removed the I-lang-easy-decision The decision needed by lang is conjectured to be easy; this dose not imply nomination. label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. S-waiting-on-review Status: The marked PR is awaiting review from a maintainer T-lang Relevant to the language team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants