Can we guarantee that `repr(rust)` union fields live at offset 0?

Đang mở
#595 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

Start by reading the linked Rust Reference sections on union layout and repr(C) unions. Determine whether fields at offset 0 can be specified consistently, including non-maximally-sized fields. Done would be a resolved layout guarantee or a documented decision against it.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A-layout S-pending-design T-lang

Per The Rust Reference:

The memory layout of a union is undefined by default (in particular, fields do not have to be at offset 0), but the #[repr(...)] attribute can be used to fix a layout.

Would anyone be opposed to at least guaranteeing that union fields always live at offset 0? It would be helpful for zerocopy.


Update: It seems that The Rust Reference doesn't even guarantee this for repr(C) unions – their size is equal to the maximum size of any field, but offset for any non-maximally-sized-field is not guaranteed.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
760
Fork
68
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/unsafe-code-guidelines

Tất cả issue của rust-lang/unsafe-code-guidelines

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.