Skip to content

Commit d8b60da

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 9e7f262 commit d8b60da

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
@@ -277,8 +277,21 @@ where
277277
let tcx = self.tcx();
278278

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

283296
(tcx.mk_place_field(base_place, field, field_ty), subpath)
284297
})

0 commit comments

Comments
 (0)