Rollup merge of #108669 - Nilstrieb:query-my-uninitness, r=compiler-errors
Allow checking whether a type allows being uninitialized This is useful for clippy ([rust-lang/clippy#10407](https://github.com/rust-lang/rust-clippy/issues/10407)) and for the future `MaybeUninit::assume_init` panics (#100423).
This commit is contained in:
commit
6ce78a31d8
3 changed files with 11 additions and 2 deletions
|
@ -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)?;
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue