clarify comments and names in check_validity_requirement

This commit is contained in:
Ralf Jung 2024-09-05 07:44:03 +02:00
parent 8cd982caa1
commit a2410425b3

View File

@ -32,15 +32,15 @@ pub fn check_validity_requirement<'tcx>(
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env }; let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
if kind == ValidityRequirement::Uninit || 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, &layout_cx, kind) check_validity_requirement_strict(layout, &layout_cx, kind)
} else { } else {
might_permit_raw_init_lax(layout, &layout_cx, kind) check_validity_requirement_lax(layout, &layout_cx, kind)
} }
} }
/// Implements the 'strict' version of the `might_permit_raw_init` checks; see that function for /// Implements the 'strict' version of the [`check_validity_requirement`] checks; see that function
/// details. /// for details.
fn might_permit_raw_init_strict<'tcx>( fn check_validity_requirement_strict<'tcx>(
ty: TyAndLayout<'tcx>, ty: TyAndLayout<'tcx>,
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
kind: ValidityRequirement, kind: ValidityRequirement,
@ -65,6 +65,8 @@ fn might_permit_raw_init_strict<'tcx>(
// This does *not* actually check that references are dereferenceable, but since all types that // This does *not* actually check that references are dereferenceable, but since all types that
// require dereferenceability also require non-null, we don't actually get any false negatives // require dereferenceability also require non-null, we don't actually get any false negatives
// due to this. // due to this.
// The value we are validating is temporary and discarded at the end of this function, so
// there is no point in reseting provenance and padding.
Ok(cx Ok(cx
.validate_operand( .validate_operand(
&allocated.into(), &allocated.into(),
@ -74,9 +76,9 @@ fn might_permit_raw_init_strict<'tcx>(
.is_ok()) .is_ok())
} }
/// Implements the 'lax' (default) version of the `might_permit_raw_init` checks; see that function for /// Implements the 'lax' (default) version of the [`check_validity_requirement`] checks; see that
/// details. /// function for details.
fn might_permit_raw_init_lax<'tcx>( fn check_validity_requirement_lax<'tcx>(
this: TyAndLayout<'tcx>, this: TyAndLayout<'tcx>,
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
init_kind: ValidityRequirement, init_kind: ValidityRequirement,
@ -141,7 +143,7 @@ fn might_permit_raw_init_lax<'tcx>(
} }
FieldsShape::Arbitrary { offsets, .. } => { FieldsShape::Arbitrary { offsets, .. } => {
for idx in 0..offsets.len() { for idx in 0..offsets.len() {
if !might_permit_raw_init_lax(this.field(cx, idx), cx, init_kind)? { if !check_validity_requirement_lax(this.field(cx, idx), cx, init_kind)? {
// We found a field that is unhappy with this kind of initialization. // We found a field that is unhappy with this kind of initialization.
return Ok(false); return Ok(false);
} }