rust-lang / rust-lang/libs-team
Request: guarantee that `Vec` field order is independent of type parameter
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 178
- Forks
- 28
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
Niche request in service of C++ interop:
I would like to rely on the fact that the order of ptr, len, and capacity fields in a Vec<T> is independent of the choice of T. This could be offered as a guarantee via the use of repr(ordered_fields) or repr(C) on Vec and RawVecInner.
I do not require a guarantee of the particular order of these fields, only that it not be dependent upon the choice of generic parameters. Having the order change across Rust compiler versions is acceptable for my usecase.
Reason: I would like to provide a layout-equivalent templated definition of Vec<T> in C++ without having to generate specializations for each choice of T. This is only possible if the order of fields in a Vec<T> is independent of the choice of T.
This is also partially a lang-team question, but asking libs first seemed appropriate to me.
Edit to add: a partial specialization which covers all ZSTs is also acceptable.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names Vec, ptr/len/capacity, RawVecInner, repr(ordered_fields), repr(C), and C++ interop, but provides no file or test. Start by tracing the layout definitions and the related libs/lang-team discussion; done means the guarantee's feasibility and acceptable validation or documentation are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- backend-api-design, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100