diff options
| author | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2024-02-28 17:55:04 -0500 |
|---|---|---|
| committer | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2024-02-28 17:55:04 -0500 |
| commit | f574c651476a43dd7ca92ef859fb501d18a8c3ff (patch) | |
| tree | 02ef97e59033a81d1c423e7fefef84f131a90c7d | |
| parent | 4dabbcb23b0dc605cdb4aa6f3499d0f053f7b600 (diff) | |
| download | rust-f574c651476a43dd7ca92ef859fb501d18a8c3ff.tar.gz rust-f574c651476a43dd7ca92ef859fb501d18a8c3ff.zip | |
simplify common prim computation
| -rw-r--r-- | compiler/rustc_abi/src/layout.rs | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index d023c869e8b..a476d83d4c7 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -813,7 +813,7 @@ where break; } }; - if let Some((old_common_prim, common_offset)) = common_prim { + if let Some((old_prim, common_offset)) = common_prim { // All variants must be at the same offset if offset != common_offset { common_prim = None; @@ -822,12 +822,12 @@ where // This is pretty conservative. We could go fancier // by realising that (u8, u8) could just cohabit with // u16 or even u32. - let new_common_prim = match (old_common_prim, prim) { + let new_prim = match (old_prim, prim) { // Allow all identical primitives. - (x, y) if x == y => Some(x), + (x, y) if x == y => x, // Allow integers of the same size with differing signedness. // We arbitrarily choose the signedness of the first variant. - (p @ Primitive::Int(x, _), Primitive::Int(y, _)) if x == y => Some(p), + (p @ Primitive::Int(x, _), Primitive::Int(y, _)) if x == y => p, // Allow integers mixed with pointers of the same layout. // We must represent this using a pointer, to avoid // roundtripping pointers through ptrtoint/inttoptr. @@ -835,22 +835,15 @@ where | (i @ Primitive::Int(..), p @ Primitive::Pointer(_)) if p.size(dl) == i.size(dl) && p.align(dl) == i.align(dl) => { - Some(p) + p } - _ => None, - }; - match new_common_prim { - Some(new_prim) => { - // Primitives are compatible. - // We may be updating the primitive here, for example from int->ptr. - common_prim = Some((new_prim, common_offset)); - } - None => { - // Primitives are incompatible. + _ => { common_prim = None; break; } - } + }; + // We may be updating the primitive here, for example from int->ptr. + common_prim = Some((new_prim, common_offset)); } else { common_prim = Some((prim, offset)); } |
