Handle normalization failures in drop elaboration

Drop elaboration looks at fields of a type, which may error when we try
to normalize them. Borrowck will have detected this if HIR typeck
didn't, but we don't delete the MIR body for errors in borrowck so
still have to handle this happening in drop elaboration by checking
whether an error has been emitted.
This commit is contained in:
Matthew Jasper 2025-01-31 18:08:09 +00:00
parent 136f777ae1
commit cde8c6f52b

View file

@ -266,8 +266,21 @@ where
let tcx = self.tcx();
assert_eq!(self.elaborator.typing_env().typing_mode, ty::TypingMode::PostAnalysis);
let field_ty =
tcx.normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args));
// The type error for normalization may have been in dropck: see
// `compute_drop_data` in rustc_borrowck, in which case we wouldn't have
// deleted the MIR body and could have an error here as well.
let field_ty = match tcx
.try_normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args))
{
Ok(t) => t,
Err(_) => Ty::new_error(
self.tcx(),
self.elaborator
.body()
.tainted_by_errors
.expect("Error in drop elaboration not found by dropck."),
),
};
(tcx.mk_place_field(base_place, field, field_ty), subpath)
})