Skip to content

Commit 8195e8b

Browse files
committed
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.
1 parent 192b35c commit 8195e8b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,21 @@ where
274274
let tcx = self.tcx();
275275

276276
assert_eq!(self.elaborator.typing_env().typing_mode, ty::TypingMode::PostAnalysis);
277-
let field_ty =
278-
tcx.normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args));
277+
// The type error for normalization may have been in dropck: see
278+
// `compute_drop_data` in rustc_borrowck, in which case we wouldn't have
279+
// deleted the MIR body and could have an error here as well.
280+
let field_ty = match tcx
281+
.try_normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args))
282+
{
283+
Ok(t) => t,
284+
Err(_) => Ty::new_error(
285+
self.tcx(),
286+
self.elaborator
287+
.body()
288+
.tainted_by_errors
289+
.expect("Error in drop elaboration not found by dropck."),
290+
),
291+
};
279292

280293
(tcx.mk_place_field(base_place, field, field_ty), subpath)
281294
})

0 commit comments

Comments
 (0)