Better error message

This commit is contained in:
Michael Goulet 2023-06-19 20:00:37 +00:00
parent dd620aa73a
commit 32f83e18ab
2 changed files with 17 additions and 2 deletions

View File

@ -156,7 +156,22 @@ fn layout_of_uncached<'tcx>(
pointee_metadata,
) {
Ok(metadata_ty) => metadata_ty,
Err(err) => return Err(LayoutError::NormalizationFailure(pointee, err)),
Err(mut err) => {
// Usually `<Ty as Pointee>::Metadata` can't be normalized because
// its struct tail cannot be normalized either, so try to get a
// more descriptive layout error here, which will lead to less confusing
// diagnostics.
match tcx.try_normalize_erasing_regions(
param_env,
tcx.struct_tail_without_normalization(pointee),
) {
Ok(_) => {},
Err(better_err) => {
err = better_err;
}
}
return Err(LayoutError::NormalizationFailure(pointee, err));
},
};
let metadata_layout = cx.layout_of(metadata_ty)?;

View File

@ -11,7 +11,7 @@ LL | std::mem::transmute::<Option<()>, Option<&Other>>(None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `Option<()>` (8 bits)
= note: target type: `Option<&Other>` (unable to determine layout for `Other` because `<Other as Pointee>::Metadata` cannot be normalized)
= note: target type: `Option<&Other>` (unable to determine layout for `Other` because `<() as Trait>::RefTarget` cannot be normalized)
error: aborting due to 2 previous errors