Skip to content

Commit 9d897cb

Browse files
committed
transmute: fix check for whether newtypes have equal size
1 parent e8e4541 commit 9d897cb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,24 @@ impl<'tcx> SizeSkeleton<'tcx> {
435435
if def.is_union() || def.variants().is_empty() || def.variants().len() > 2 {
436436
return Err(err);
437437
}
438+
// Only default repr types.
439+
{
440+
// We can ignore the seed and some particular flags but we have to check
441+
// everything else.
442+
let ReprOptions { int, align, pack, flags, scalable, field_shuffle_seed: _ } =
443+
def.repr();
444+
let ignored_flags = ReprFlags::IS_TRANSPARENT
445+
| ReprFlags::IS_LINEAR
446+
| ReprFlags::RANDOMIZE_LAYOUT;
447+
if int.is_some()
448+
|| align.is_some()
449+
|| pack.is_some()
450+
|| flags.difference(ignored_flags) != Default::default()
451+
|| scalable.is_some()
452+
{
453+
return Err(err);
454+
}
455+
}
438456

439457
// Get a zero-sized variant or a pointer newtype.
440458
let zero_or_ptr_variant = |i| {

0 commit comments

Comments
 (0)