Skip to content

Commit 6d16857

Browse files
committed
fix(upstream): unnormalized migration
1 parent 3a8a8f6 commit 6d16857

3 files changed

Lines changed: 28 additions & 32 deletions

File tree

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mir/elaborate_drop.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_index::Idx;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::adjustment::PointerCoercion;
1313
use rustc_middle::ty::util::IntTypeExt;
14-
use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt, Unnormalized};
14+
use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt};
1515
use rustc_middle::{span_bug, traits};
1616
use rustc_span::{DUMMY_SP, Spanned, dummy_spanned};
1717
use tracing::{debug, instrument};
@@ -371,7 +371,9 @@ where
371371
bug!();
372372
};
373373
let obj_ptr_ty = Ty::new_mut_ptr(tcx, drop_ty);
374-
let unwrap_ty = adt_def.non_enum_variant().fields[FieldIdx::ZERO].ty(tcx, adt_args);
374+
let unwrap_ty = adt_def.non_enum_variant().fields[FieldIdx::ZERO]
375+
.ty(tcx, adt_args)
376+
.skip_norm_wip();
375377
let obj_ref_place = Place::from(self.new_temp(unwrap_ty));
376378
call_statements.push(self.assign(
377379
obj_ref_place,
@@ -566,19 +568,11 @@ where
566568
}
567569
}
568570
let field_ty = field.ty(tcx, args);
569-
let field_ty = match tcx.try_normalize_erasing_regions(
570-
self.elaborator.typing_env(),
571-
Unnormalized::new_wip(field_ty),
572-
) {
573-
Ok(t) => t,
574-
Err(_) => Ty::new_error(
575-
self.tcx(),
576-
self.tcx().dcx().span_delayed_bug(
577-
self.elaborator.body().span,
578-
"Error normalizing in drop elaboration.",
579-
),
580-
),
581-
};
571+
// We silently leave an unnormalized type here to support polymorphic drop
572+
// elaboration for users of rustc internal APIs
573+
let field_ty = tcx
574+
.try_normalize_erasing_regions(self.elaborator.typing_env(), field_ty)
575+
.unwrap_or(field_ty.skip_norm_wip());
582576

583577
(tcx.mk_place_field(base_place, field_idx, field_ty), subpath)
584578
})
@@ -781,9 +775,13 @@ where
781775
) -> BasicBlock {
782776
// drop glue is sent straight to codegen
783777
// box cannot be directly dereferenced
784-
let unique_ty = adt.non_enum_variant().fields[FieldIdx::ZERO].ty(self.tcx(), args);
778+
let unique_ty = adt.non_enum_variant().fields[FieldIdx::ZERO]
779+
.ty(self.tcx(), args)
780+
.skip_norm_wip();
785781
let unique_variant = unique_ty.ty_adt_def().unwrap().non_enum_variant();
786-
let nonnull_ty = unique_variant.fields[FieldIdx::ZERO].ty(self.tcx(), args);
782+
let nonnull_ty = unique_variant.fields[FieldIdx::ZERO]
783+
.ty(self.tcx(), args)
784+
.skip_norm_wip();
787785
let ptr_ty = Ty::new_imm_ptr(self.tcx(), args[0].expect_ty());
788786

789787
let unique_place = self
@@ -954,10 +952,12 @@ where
954952
have_otherwise = true;
955953

956954
let typing_env = self.elaborator.typing_env();
957-
let have_field_with_drop_glue = variant
958-
.fields
959-
.iter()
960-
.any(|field| field.ty(tcx, args).needs_drop(tcx, typing_env));
955+
let have_field_with_drop_glue = variant.fields.iter().any(|field| {
956+
field
957+
.ty(tcx, args)
958+
.skip_norm_wip()
959+
.needs_drop(tcx, typing_env)
960+
});
961961
if have_field_with_drop_glue {
962962
have_otherwise_with_drop_glue = true;
963963
}

src/monomorphize_collector.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -960,14 +960,10 @@ pub fn find_tails_for_unsizing<'tcx>(
960960
};
961961
let coerce_field = &source_adt_def.non_enum_variant().fields[coerce_index];
962962
// We're getting a possibly unnormalized type, so normalize it.
963-
let source_field = tcx.normalize_erasing_regions(
964-
typing_env,
965-
Unnormalized::new_wip(coerce_field.ty(*tcx, source_args)),
966-
);
967-
let target_field = tcx.normalize_erasing_regions(
968-
typing_env,
969-
Unnormalized::new_wip(coerce_field.ty(*tcx, target_args)),
970-
);
963+
let source_field =
964+
tcx.normalize_erasing_regions(typing_env, coerce_field.ty(*tcx, source_args));
965+
let target_field =
966+
tcx.normalize_erasing_regions(typing_env, coerce_field.ty(*tcx, target_args));
971967
find_tails_for_unsizing(tcx, typing_env, source_field, target_field)
972968
}
973969
_ => bug!(

0 commit comments

Comments
 (0)