Repository: rust-lang/rust
File: compiler/rustc_target/src/callconv/mod.rs (Rust)

Code before:
                }

                _ => {}
            }
        }
    }
}

/// Determines whether `layout` contains no uninit bytes (no padding, no unions),
/// using only the computed layout.
///
/// Conservative: returns `false` for anything it cannot prove fully initialized,
/// including multi-variant enums and SIMD vectors.
// FIXME: extend to multi-variant enums (per-variant padding analysis needed).
fn layout_is_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool
where
    Ty: TyAbiInterface<'a, C> + Copy,
    C: HasDataLayout,
{
    match layout.backend_repr {
        BackendRepr::Scalar(scalar) => !scalar.is_uninit_valid(),
        BackendRepr::ScalarPair(s1, s2) => {
            !s1.is_uninit_valid()
                && !s2.is_uninit_valid()
                && s1.size(cx) + s2.size(cx) == layout.size
        }
        BackendRepr::Memory { .. } => match layout.fields {
            FieldsShape::Primitive | FieldsShape::Union(_) => false,
            // Array elements are at stride offsets with no inter-element gaps.
            FieldsShape::Array { stride: _, count } => {
                count == 0 || layout_is_noundef(layout.field(cx, 0), cx)
            }
            FieldsShape::Arbitrary { .. } => {
                // With `Variants::Multiple`, `layout.fields` only covers shared
                // bytes (niche/discriminant); per-variant data is absent, so
                // full coverage cannot be proven.
                matches!(layout.variants, Variants::Single { .. }) && fields_are_noundef(layout, cx)
            }
        },
        BackendRepr::SimdVector { .. } | BackendRepr::ScalableVector { .. } => false,
    }
}

/// Returns `true` if the fields of `layout` contiguously cover bytes `0..layout.size`
/// with no padding gaps and each field is recursively `layout_is_noundef`.
fn fields_are_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool
where
    Ty: TyAbiInterface<'a, C> + Copy,
    C: HasDataLayout,
{
    let mut cursor = Size::ZERO;

Review comment (suggestion):
```suggestion
                // Ensure there is no padding.
                && s1.size(cx) + s2.size(cx) == layout.size
```

Code after:
                }

                _ => {}
            }
        }
    }
}

/// Determines whether `layout` contains no uninit bytes (no padding, no unions),
/// using only the computed layout.
///
/// Conservative: returns `false` for anything it cannot prove fully initialized,
/// including multi-variant enums and SIMD vectors.
// FIXME: extend to multi-variant enums (per-variant padding analysis needed).
fn layout_is_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool
where
    Ty: TyAbiInterface<'a, C> + Copy,
    C: HasDataLayout,
{
    match layout.backend_repr {
        BackendRepr::Scalar(scalar) => !scalar.is_uninit_valid(),
        BackendRepr::ScalarPair(s1, s2) => {
            !s1.is_uninit_valid()
                && !s2.is_uninit_valid()
                // Ensure there is no padding.
                && s1.size(cx) + s2.size(cx) == layout.size
        }
        BackendRepr::Memory { .. } => match layout.fields {
            FieldsShape::Primitive | FieldsShape::Union(_) => false,
            // Array elements are at stride offsets with no inter-element gaps.
            FieldsShape::Array { stride: _, count } => {
                count == 0 || layout_is_noundef(layout.field(cx, 0), cx)
            }
            FieldsShape::Arbitrary { .. } => {
                // With `Variants::Multiple`, `layout.fields` only covers shared
                // bytes (niche/discriminant); per-variant data is absent, so
                // full coverage cannot be proven.
                matches!(layout.variants, Variants::Single { .. }) && fields_are_noundef(layout, cx)
            }
        },
        BackendRepr::SimdVector { .. } | BackendRepr::ScalableVector { .. } => false,
    }
}

/// Returns `true` if the fields of `layout` contiguously cover bytes `0..layout.size`
/// with no padding gaps and each field is recursively `layout_is_noundef`.
fn fields_are_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool
where
    Ty: TyAbiInterface<'a, C> + Copy,
    C: HasDataLayout,
{