From 20bb56ebfd4a9d8b21de8f8e75e062ae48d04810 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 2 Nov 2022 00:38:43 +0000 Subject: [PATCH] Use codegen_select in vtable_trait_upcasting_coercion_new_vptr_slot --- .../rustc_trait_selection/src/traits/mod.rs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 0bf54c096cd40..4e764d70ba9de 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -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) {