Skip to content

Commit fd5be23

Browse files
committed
fix for the issue #92464
1 parent 38c22af commit fd5be23

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_middle/src/ty/layout.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
13101310
},
13111311
};
13121312
let mut abi = Abi::Aggregate { sized: true };
1313-
if tag.value.size(dl) == size {
1313+
1314+
// Without latter check aligned enums with custom discriminant values
1315+
// Would result in ICE see the issue #92464 for more info
1316+
if tag.value.size(dl) == size || variants.iter().all(|layout| layout.is_empty()) {
13141317
abi = Abi::Scalar(tag);
13151318
} else {
13161319
// Try to use a ScalarPair for all tagged enums.

src/test/ui/aligned_enum_cast.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
// allows aligned custom discriminant enums to cast into other types
3+
// See the issue #92464 for more info
4+
#[allow(dead_code)]
5+
#[repr(align(8))]
6+
enum Aligned {
7+
Zero = 0,
8+
One = 1,
9+
}
10+
11+
fn main() {
12+
let aligned = Aligned::Zero;
13+
let fo = aligned as u8;
14+
println!("foo {}",fo);
15+
}

0 commit comments

Comments
 (0)