E0084 rejects every `#[repr]` on zero-variant enums, including representations the language allows

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
47/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

The issue points to the zero-variant enum #[repr] validation in rustc but names no source files or tests. Start by tracing the E0084 diagnostic and its UI tests, then compare the checks for primitive and C representations with the allowed Rust and align cases described here. Done means the permitted forms compile, the forbidden forms still produce errors, and regression tests cover the distinctions.

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

Mô tả

A-enum A-repr A-uninhabited-types C-bug needs-triage T-compiler T-lang

Split out from #139703, where @hanna-kruppe and @fmease pointed out that #[repr(align(N))] and #[repr(Rust)] are rejected on empty enums.

What the language says

The Reference only forbids two kinds of representation on zero-variant enums:

Nothing else is forbidden. The Reference even assumes other representations exist for them: "Enums (without a primitive representation) with no variants are zero sized." layout.repr.alignment.enum also allows align on any enum, and defines it as equivalent to wrapping the enum in a newtype struct with the same align modifier.

What rustc does

rustc enforces a stricter rule: a zero-variant enum can't have any #[repr] attribute at all.

Attribute on enum E {} Reference rustc
#[repr(u8)], #[repr(isize)], … error E0084
#[repr(C)] error E0084
#[repr(Rust)] allowed E0084
#[repr(align(8))] allowed E0084
#[repr(C, align(8))] error (because of C) E0084
#[repr()] allowed (no effect) E0084, plus an "unused attribute" warning
History

The original check (2014) only rejected representations that set the discriminant type, which matches the Reference. It was broadened to "any #[repr] attribute" in ba11640179b (#40008, 2017), during a refactor that doesn't appear to have intended a language change. Representations stabilized after that, such as align on enums and explicit Rust, were rejected on zero-variant enums from the start.

@rustbot label +A-enum +A-repr +A-uninhabited-types +C-bug +T-compiler +T-lang

Ngôn ngữ chính
Rust
Star
123k
Fork
16.6k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
532

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

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/rust

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

Issue tương tự

Thêm issue về Rust

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.