E0084 rejects every `#[repr]` on zero-variant enums, including representations the language allows
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
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ả
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:
- layout.repr.primitive.constraint: "It is an error for zero-variant enums to have a primitive representation."
- layout.repr.c.constraint: the
Crepresentation is an error for 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/rust
-
strictly_dominates missing a `=`Đang mởC-bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
rust-lang/rust#166722 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-run-make C-bug T-bootstrap
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`Đang mởrelnotes relnotes-tracking-issue T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/rust
Issue tương tự
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug core-lang
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
max-sixty/worktrunk#4939 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày