Skip to content

Commit

Permalink
clarify comments and names in check_validity_requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 8, 2024
1 parent 8cd982c commit a241042
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions compiler/rustc_const_eval/src/util/check_validity_requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub fn check_validity_requirement<'tcx>(

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 {
might_permit_raw_init_strict(layout, &layout_cx, kind)
check_validity_requirement_strict(layout, &layout_cx, kind)
} 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
/// details.
fn might_permit_raw_init_strict<'tcx>(
/// Implements the 'strict' version of the [`check_validity_requirement`] checks; see that function
/// for details.
fn check_validity_requirement_strict<'tcx>(
ty: TyAndLayout<'tcx>,
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
kind: ValidityRequirement,
Expand All @@ -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
// require dereferenceability also require non-null, we don't actually get any false negatives
// 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
.validate_operand(
&allocated.into(),
Expand All @@ -74,9 +76,9 @@ fn might_permit_raw_init_strict<'tcx>(
.is_ok())
}

/// Implements the 'lax' (default) version of the `might_permit_raw_init` checks; see that function for
/// details.
fn might_permit_raw_init_lax<'tcx>(
/// Implements the 'lax' (default) version of the [`check_validity_requirement`] checks; see that
/// function for details.
fn check_validity_requirement_lax<'tcx>(
this: TyAndLayout<'tcx>,
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
init_kind: ValidityRequirement,
Expand Down Expand Up @@ -141,7 +143,7 @@ fn might_permit_raw_init_lax<'tcx>(
}
FieldsShape::Arbitrary { offsets, .. } => {
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.
return Ok(false);
}
Expand Down

0 comments on commit a241042

Please sign in to comment.