Skip to content

Commit 9e5c56e

Browse files
committed
only insert the principal trait in drop_glue
1 parent 67ba354 commit 9e5c56e

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/librustc_mir/monomorphize/collector.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,14 +1034,12 @@ fn create_mono_items_for_vtable_methods<'a, 'tcx>(
10341034
let drop_glue_instance = visit_drop_use(tcx, impl_ty, false, output);
10351035

10361036
if let Some(principal) = trait_sty.principal() {
1037-
let drop_glue = drop_glue.entry(drop_glue_instance).or_default();
1038-
1039-
// the principal trait may not have any method but we must consider it in drop glue call
1040-
// metadata
1041-
drop_glue.insert(tcx.normalize_erasing_late_bound_regions(
1042-
ty::ParamEnv::reveal_all(),
1043-
&principal,
1044-
));
1037+
// we only consider the principal trait for the drop glue call metadata
1038+
drop_glue.entry(drop_glue_instance).or_default().insert(
1039+
tcx.normalize_erasing_late_bound_regions(
1040+
ty::ParamEnv::reveal_all(),
1041+
&principal,
1042+
));
10451043

10461044
let poly_trait_ref = principal.with_self_ty(tcx, impl_ty);
10471045
assert!(!poly_trait_ref.has_escaping_bound_vars());
@@ -1064,8 +1062,7 @@ fn create_mono_items_for_vtable_methods<'a, 'tcx>(
10641062
.filter(|instance| should_monomorphize_locally(tcx, &instance));
10651063

10661064
for instance in methods {
1067-
if let Some((trait_ref, _)) = instance.trait_ref_and_method(tcx) {
1068-
drop_glue.insert(trait_ref);
1065+
if instance.trait_ref_and_method(tcx).is_some() {
10691066
dynamic_dispatch.insert(instance);
10701067
}
10711068

@@ -1354,10 +1351,9 @@ fn collect_miri<'a, 'tcx>(
13541351
}
13551352
}).next();
13561353

1357-
if let Some(drop_glue_instance) = drop_glue_instance {
1358-
// FIXME(japaric) if the principal trait happens to have no methods the `for` loop
1359-
// below won't insert it into `drop_glue`; we must include it separately here
1360-
let drop_glue = drop_glue.entry(drop_glue_instance).or_default();
1354+
if let Some(_drop_glue_instance) = drop_glue_instance {
1355+
// FIXME(japaric) we need to insert only the principal trait into `drop_glue`
1356+
// drop_glue.entry(drop_glue_instance).or_default().insert(???);
13611357

13621358
// trait object in const / static context
13631359
for ((), inner) in alloc.relocations.values() {
@@ -1367,9 +1363,8 @@ fn collect_miri<'a, 'tcx>(
13671363
if should_monomorphize_locally(tcx, &instance) {
13681364
trace!("collecting {:?} with {:#?}", alloc_id, instance);
13691365

1370-
if let Some((trait_ref, _)) = instance.trait_ref_and_method(tcx) {
1366+
if instance.trait_ref_and_method(tcx).is_some() {
13711367
dynamic_dispatch.insert(instance);
1372-
drop_glue.insert(trait_ref);
13731368
}
13741369

13751370
output.push(create_fn_mono_item(instance));

0 commit comments

Comments
 (0)