Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use codegen_select in vtable_trait_upcasting_coercion_new_vptr_slot #103861

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,25 +933,13 @@ pub fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>(
def_id: unsize_trait_did,
substs: tcx.mk_substs_trait(source, &[target.into()]),
};
let obligation = Obligation::new(
ObligationCause::dummy(),
ty::ParamEnv::reveal_all(),
ty::Binder::dummy(ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
}),
);

let infcx = tcx.infer_ctxt().build();
let mut selcx = SelectionContext::new(&infcx);
let implsrc = selcx.select(&obligation).unwrap();

let Some(ImplSource::TraitUpcasting(implsrc_traitcasting)) = implsrc else {
bug!();
};

implsrc_traitcasting.vtable_vptr_slot
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) {
Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => {
implsrc_traitcasting.vtable_vptr_slot
}
otherwise => bug!("expected TraitUpcasting candidate, got {otherwise:?}"),
}
}

pub fn provide(providers: &mut ty::query::Providers) {
Expand Down