Skip to content

Commit f574c65

Browse files
simplify common prim computation
1 parent 4dabbcb commit f574c65

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

compiler/rustc_abi/src/layout.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ where
813813
break;
814814
}
815815
};
816-
if let Some((old_common_prim, common_offset)) = common_prim {
816+
if let Some((old_prim, common_offset)) = common_prim {
817817
// All variants must be at the same offset
818818
if offset != common_offset {
819819
common_prim = None;
@@ -822,35 +822,28 @@ where
822822
// This is pretty conservative. We could go fancier
823823
// by realising that (u8, u8) could just cohabit with
824824
// u16 or even u32.
825-
let new_common_prim = match (old_common_prim, prim) {
825+
let new_prim = match (old_prim, prim) {
826826
// Allow all identical primitives.
827-
(x, y) if x == y => Some(x),
827+
(x, y) if x == y => x,
828828
// Allow integers of the same size with differing signedness.
829829
// We arbitrarily choose the signedness of the first variant.
830-
(p @ Primitive::Int(x, _), Primitive::Int(y, _)) if x == y => Some(p),
830+
(p @ Primitive::Int(x, _), Primitive::Int(y, _)) if x == y => p,
831831
// Allow integers mixed with pointers of the same layout.
832832
// We must represent this using a pointer, to avoid
833833
// roundtripping pointers through ptrtoint/inttoptr.
834834
(p @ Primitive::Pointer(_), i @ Primitive::Int(..))
835835
| (i @ Primitive::Int(..), p @ Primitive::Pointer(_))
836836
if p.size(dl) == i.size(dl) && p.align(dl) == i.align(dl) =>
837837
{
838-
Some(p)
838+
p
839839
}
840-
_ => None,
841-
};
842-
match new_common_prim {
843-
Some(new_prim) => {
844-
// Primitives are compatible.
845-
// We may be updating the primitive here, for example from int->ptr.
846-
common_prim = Some((new_prim, common_offset));
847-
}
848-
None => {
849-
// Primitives are incompatible.
840+
_ => {
850841
common_prim = None;
851842
break;
852843
}
853-
}
844+
};
845+
// We may be updating the primitive here, for example from int->ptr.
846+
common_prim = Some((new_prim, common_offset));
854847
} else {
855848
common_prim = Some((prim, offset));
856849
}

0 commit comments

Comments
 (0)