Fix the reporting of layout normalization failures in transmute checks - #159456
Fix the reporting of layout normalization failures in transmute checks#159456meta-legend wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @dingxiangfei2009 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
r=me after rebase |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot review |
|
The author has rebased. I've also gone ahead and applied the following purely stylistic patch: let normalize = |ty: Unnormalized<'tcx, Ty<'tcx>>| -> Result<Ty<'tcx>, ErrorGuaranteed> {
- let unnormalized_ty = ty.skip_normalization();
tcx.try_normalize_erasing_regions(typing_env, ty).map_err(|err| {
- tcx.dcx()
- .struct_span_err(
- span,
- LayoutError::NormalizationFailure(unnormalized_ty, err).to_string(),
- )
- .emit()
+ let err = LayoutError::NormalizationFailure(ty.skip_normalization(), err);
+ tcx.dcx().struct_span_err(span, err.to_string()).emit()
})
};
@bors r=cjgillot rollup |
Fix the reporting of layout normalization failures in transmute checks Fixes rust-lang#149588. "check_transmute" normalized the source and target types before computing their size skeletons. When that normalization failed, it created a {type error} placeholder and continued into the generic transmute-size diagnostic. This hid the actual layout failure and produced an unhelpful E0512 message. This changes transmute checking to report the layout normalization failure directly and return early. The diagnostic now explains that rustc cannot determine the layout because the associated type cannot be normalized, instead of showing `{type error}` as the source type. I also updated the existing ./tests/ui/layout/normalization-failure.rs test to cover the corrected diagnostic.
…uwer Rollup of 17 pull requests Successful merges: - #161187 (add `Complex<T>` layout tests for straightforward targets) - #161524 (Put back `tests/rustdoc-gui/search-result-display.goml`) - #161592 (core: refactor tests/pattern.rs tests) - #161602 (Fix flakyness issue for `tests/rustdoc-gui/headers-color.goml`) - #155254 (Recover on attribute in use tree) - #158695 (Replace `CrateDump` with the Debug impl from `CStore`) - #159456 (Fix the reporting of layout normalization failures in transmute checks) - #160452 (-Ctarget-feature is not unsafe (any more)) - #161007 (tests/ui/union/union-nodrop.rs: fix typo "expressios") - #161166 (add crashtests [5/N], remove unused aux files ) - #161569 (Bump cfg_aliases to 0.2.2) - #161573 (re-bless `pretty-std` on windows) - #161588 (update eyre) - #161589 (std: reduce visibility of some internal OsStr related types) - #161598 ([Bootstrap] Pass exact CI `llvm-config` executable path) - #161601 (Path: use optimized is_empty() method) - #161604 (coretests: Add a few tests for backward multibyte predicate)
Fixes #149588.
"check_transmute" normalized the source and target types before computing their size skeletons. When that normalization failed, it created a {type error} placeholder and continued into the generic transmute-size diagnostic. This hid the actual layout failure and produced an unhelpful E0512 message.
This changes transmute checking to report the layout normalization failure directly and return early. The diagnostic now explains that rustc cannot determine the layout because the associated type cannot be normalized, instead of showing
{type error}as the source type.I also updated the existing ./tests/ui/layout/normalization-failure.rs test to cover the corrected diagnostic.