1
Fork 0

Allow checking whether a type allows being uninitialized

This is useful for clippy and for the future `MaybeUninit::assume_init`
panics.
This commit is contained in:
Nilstrieb 2023-03-02 18:33:48 +00:00
parent 7e966bcd03
commit 10a69de5fd
3 changed files with 11 additions and 2 deletions

View file

@ -444,6 +444,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
ty
),
ValidityRequirement::Uninit => bug!("assert_uninit_valid doesn't exist"),
};
M::abort(self, msg)?;

View file

@ -30,7 +30,7 @@ pub fn check_validity_requirement<'tcx>(
return Ok(!layout.abi.is_uninhabited());
}
if tcx.sess.opts.unstable_opts.strict_init_checks {
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
might_permit_raw_init_strict(layout, tcx, kind)
} else {
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
@ -99,6 +99,9 @@ fn might_permit_raw_init_lax<'tcx>(
}
s.valid_range(cx).contains(val)
}
ValidityRequirement::Uninit => {
bug!("ValidityRequirement::Uninit should have been handled above")
}
}
};