Skip to content

Commit cde8c6f

Browse files
committedFeb 17, 2025
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 136f777 commit cde8c6f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎compiler/rustc_mir_transform/src/elaborate_drop.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,21 @@ where
266266
let tcx = self.tcx();
267267

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

272285
(tcx.mk_place_field(base_place, field, field_ty), subpath)
273286
})

0 commit comments

Comments
 (0)
Please sign in to comment.