about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authormsizanoen <msizanoen@qtmlabs.xyz>2023-09-03 15:58:21 +0700
committermsizanoen <msizanoen@qtmlabs.xyz>2023-09-19 12:06:33 +0200
commit751ecde0640f1d079515964e72e2646e82cb25f4 (patch)
tree2f04ddbee8e786e5505cd3f099a3520fa63e0daf /compiler/rustc_middle/src
parentae9c330629f1fb03a636cb8af367fead024793db (diff)
rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member
This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed
through an `extern "C"` function.

Fixes https://github.com/rust-lang/rust/issues/115481.
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index 9a0e72d7b64..8b425ce0267 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -1118,6 +1118,10 @@ where
     fn is_unit(this: TyAndLayout<'tcx>) -> bool {
         matches!(this.ty.kind(), ty::Tuple(list) if list.len() == 0)
     }
+
+    fn is_transparent(this: TyAndLayout<'tcx>) -> bool {
+        matches!(this.ty.kind(), ty::Adt(def, _) if def.repr().transparent())
+    }
 }
 
 /// Calculates whether a function's ABI can unwind or not.