From cacc0829ffa012e1e6a84ad35160533431a2d269 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Wed, 8 May 2024 18:22:14 +0530 Subject: [PATCH] Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes an ICE that occurred when the struct in question has an error --- compiler/rustc_middle/src/ty/layout.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index f17413af77700..8873025e440aa 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -338,13 +338,14 @@ impl<'tcx> SizeSkeleton<'tcx> { pointee, |ty| match tcx.try_normalize_erasing_regions(param_env, ty) { Ok(ty) => ty, - Err(_e) => { - if let Some(guar) = tcx.dcx().has_errors() { - Ty::new_error(tcx, guar) - } else { - bug!("normalization failed, but no errors reported"); - } - } + Err(e) => Ty::new_error_with_message( + tcx, + DUMMY_SP, + format!( + "normalization failed for {} but no errors reported", + e.get_type_for_failure() + ), + ), }, || {}, );