Skip to content

Commit f77a407

Browse files
committed
Allow uninhabited types in generator interiors
Drop tracking in the generator interior type checking pass would count all values in unreachable code as dropped (e.g. code after a call to a function with an uninhabited return type), which would lead to those values not being included in the witness type. This resulted in the type checker being more precise than the corresponding sanity check in the MIR transform. This patch changes the check in the MIR code to match the results of typeck by skipping uninhabited types.
1 parent cc9f16b commit f77a407

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/rustc_mir_transform/src/generator.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,15 @@ fn sanitize_witness<'tcx>(
749749
}
750750
let decl_ty = tcx.normalize_erasing_regions(param_env, decl.ty);
751751

752+
let is_uninhabited = tcx.is_ty_uninhabited_from(
753+
tcx.parent_module(tcx.hir().local_def_id_to_hir_id(did.expect_local())).to_def_id(),
754+
decl_ty,
755+
param_env,
756+
);
757+
752758
// Sanity check that typeck knows about the type of locals which are
753759
// live across a suspension point
754-
if !allowed.contains(&decl_ty) && !allowed_upvars.contains(&decl_ty) {
760+
if !is_uninhabited && !allowed.contains(&decl_ty) && !allowed_upvars.contains(&decl_ty) {
755761
span_bug!(
756762
body.span,
757763
"Broken MIR: generator contains type {} in MIR, \

0 commit comments

Comments
 (0)