Skip to content

Commit f837da7

Browse files
authored
Rollup merge of rust-lang#106201 - estebank:verbose-transparent, r=compiler-errors
Emit fewer errors on invalid `#[repr(transparent)]` on `enum` Fix rust-lang#68420.
2 parents 45d6f02 + 50c1be1 commit f837da7

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
10601060

10611061
if adt.variants().len() != 1 {
10621062
bad_variant_count(tcx, adt, tcx.def_span(adt.did()), adt.did());
1063-
if adt.variants().is_empty() {
1064-
// Don't bother checking the fields. No variants (and thus no fields) exist.
1065-
return;
1066-
}
1063+
// Don't bother checking the fields.
1064+
return;
10671065
}
10681066

10691067
// For each field, figure out if it's known to be a ZST and align(1), with "known"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::mem::size_of;
2+
3+
#[repr(transparent)]
4+
enum Foo { //~ ERROR E0731
5+
A(u8), B(u8),
6+
}
7+
8+
fn main() {
9+
println!("Foo: {}", size_of::<Foo>());
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0731]: transparent enum needs exactly one variant, but has 2
2+
--> $DIR/transparent-enum-too-many-variants.rs:4:1
3+
|
4+
LL | enum Foo {
5+
| ^^^^^^^^ needs exactly one variant, but has 2
6+
LL | A(u8), B(u8),
7+
| - - too many variants in `Foo`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0731`.

0 commit comments

Comments
 (0)