pub fn check_validity_requirement<'tcx>(
    tcx: TyCtxt<'tcx>,
    kind: ValidityRequirement,
    param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
) -> Result<bool, &'tcx LayoutError<'tcx>>
Expand description

Determines if this type permits “raw” initialization by just transmuting some memory into an instance of T.

init_kind indicates if the memory is zero-initialized or left uninitialized. We assume uninitialized memory is mitigated by filling it with 0x01, which reduces the chance of causing LLVM UB.

By default we check whether that operation would cause LLVM UB, i.e., whether the LLVM IR we generate has UB or not. This is a mitigation strategy, which is why we are okay with accepting Rust UB as long as there is no risk of miscompilations. The strict_init_checks can be set to do a full check against Rust UB instead (in which case we will also ignore the 0x01-filling and to the full uninit check).