Only insert uninit_decl if check_field_offset is non-empty
@@ -2172,17 +2172,10 @@ impl CodeGenerator for CompInfo {
let should_skip_field_offset_checks =
is_opaque || too_many_base_vtables;
- let (uninit_decl, check_field_offset) =
- if should_skip_field_offset_checks {
- (None, vec![])
+ let check_field_offset = if should_skip_field_offset_checks
+ {
+ vec![]
} else {
- (
- Some(quote! {
- // Use a shared MaybeUninit so that rustc with
- // opt-level=0 doesn't take too much stack
- // space, see #2218.
- const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit();
- }),
self.fields()
.iter()
.filter_map(|field| match *field {
@@ -2207,7 +2200,17 @@ impl CodeGenerator for CompInfo {
})
})
.collect()
- )
+ };
+
+ let uninit_decl = if !check_field_offset.is_empty() {
+ Some(quote! {
+ // Use a shared MaybeUninit so that rustc with
+ // opt-level=0 doesn't take too much stack space,
+ // see #2218.
+ const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit();
+ })
+ } else {
+ None
};
let item = quote! {
@@ -2217,7 +2220,6 @@ impl CodeGenerator for CompInfo {
assert_eq!(#size_of_expr,
#size,
concat!("Size of: ", stringify!(#canonical_ident)));
-
#check_struct_align
#( #check_field_offset )*
}
