Skip to content

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 19, 2023
1 parent dd620aa commit 32f83e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 32f83e1

Please sign in to comment.