Skip to content

Commit

Permalink
Auto merge of rust-lang#88135 - crlf0710:trait_upcasting_part_3, r=ni…
Browse files Browse the repository at this point in the history
…komatsakis

Trait upcasting coercion (part 3)

By using separate candidates for each possible choice, this fixes type-checking issues in previous commits.

r? `@nikomatsakis`
  • Loading branch information
bors committed Aug 21, 2021
2 parents 8b8ab5f + 03ed8c8 commit 21fff2c
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,10 @@ pub(crate) fn unsized_info<'tcx>(
if data_a.principal_def_id() == data_b.principal_def_id() {
return old_info;
}
// trait upcasting coercion

// if both of the two `principal`s are `None`, this function would have returned early above.
// and if one of the two `principal`s is `None`, typechecking would have rejected this case.
let principal_a = data_a
.principal()
.expect("unsized_info: missing principal trait for trait upcasting coercion");
let principal_b = data_b
.principal()
.expect("unsized_info: missing principal trait for trait upcasting coercion");

let vptr_entry_idx = fx.tcx.vtable_trait_upcasting_coercion_new_vptr_slot((
principal_a.with_self_ty(fx.tcx, source),
principal_b.with_self_ty(fx.tcx, source),
));
// trait upcasting coercion
let vptr_entry_idx =
fx.tcx.vtable_trait_upcasting_coercion_new_vptr_slot((source, target));

if let Some(entry_idx) = vptr_entry_idx {
let entry_idx = u32::try_from(entry_idx).unwrap();
Expand Down

0 comments on commit 21fff2c

Please sign in to comment.