@@ -172,6 +172,8 @@ pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug {
172
172
fn is_tuple ( this : TyAndLayout < ' a , Self > ) -> bool ;
173
173
fn is_unit ( this : TyAndLayout < ' a , Self > ) -> bool ;
174
174
fn is_transparent ( this : TyAndLayout < ' a , Self > ) -> bool ;
175
+ /// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
176
+ fn is_pass_indirectly_in_non_rustic_abis_flag_set ( this : TyAndLayout < ' a , Self > ) -> bool ;
175
177
}
176
178
177
179
impl < ' a , Ty > TyAndLayout < ' a , Ty > {
@@ -269,6 +271,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
269
271
Ty :: is_transparent ( self )
270
272
}
271
273
274
+ /// If this method returns `true`, then this type should always have a `PassMode` of
275
+ /// `Indirect { on_stack: false, .. }` when being used as the argument type of a function with a
276
+ /// non-Rustic ABI (this is true for structs annotated with the
277
+ /// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute).
278
+ ///
279
+ /// This function handles transparent types automatically.
280
+ pub fn pass_indirectly_in_non_rustic_abis < C > ( mut self , cx : & C ) -> bool
281
+ where
282
+ Ty : TyAbiInterface < ' a , C > + Copy ,
283
+ {
284
+ while self . is_transparent ( )
285
+ && let Some ( ( _, field) ) = self . non_1zst_field ( cx)
286
+ {
287
+ self = field;
288
+ }
289
+ Ty :: is_pass_indirectly_in_non_rustic_abis_flag_set ( self )
290
+ }
291
+
272
292
/// Finds the one field that is not a 1-ZST.
273
293
/// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields.
274
294
pub fn non_1zst_field < C > ( & self , cx : & C ) -> Option < ( FieldIdx , Self ) >
0 commit comments