1
Fork 0

Don't try to compute the layout of generic types.

This commit is contained in:
Oli Scherer 2022-11-03 09:43:52 +00:00
parent 2bed079103
commit ccaa28bf69

View file

@ -2504,32 +2504,32 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
}); });
// Check if this ADT has a constrained layout (like `NonNull` and friends). // Check if this ADT has a constrained layout (like `NonNull` and friends).
let layout = cx.tcx.layout_of(cx.param_env.and(ty)).unwrap(); if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) {
match &layout.abi {
match &layout.abi { Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => {
Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => { let range = scalar.valid_range(cx);
let range = scalar.valid_range(cx); if !range.contains(0) {
if !range.contains(0) { return Some(
Some( InitError::from(format!("`{}` must be non-null", ty))
InitError::from(format!("`{}` must be non-null", ty)).nested(field_err), .nested(field_err),
) );
} else if init == InitKind::Uninit && !scalar.is_always_valid(cx) { } else if init == InitKind::Uninit && !scalar.is_always_valid(cx) {
// Prefer reporting on the fields over the entire struct for uninit, // Prefer reporting on the fields over the entire struct for uninit,
// as the information bubbles out and it may be unclear why the type can't // as the information bubbles out and it may be unclear why the type can't
// be null from just its outside signature. // be null from just its outside signature.
Some( return Some(
InitError::from(format!( InitError::from(format!(
"`{}` must be initialized inside its custom valid range", "`{}` must be initialized inside its custom valid range",
ty, ty,
)) ))
.nested(field_err), .nested(field_err),
) );
} else { }
field_err
} }
_ => {}
} }
_ => field_err,
} }
field_err
} }
/// Return `Some` only if we are sure this type does *not* /// Return `Some` only if we are sure this type does *not*