summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-06 14:03:59 +0000
committerbors <bors@rust-lang.org>2022-11-06 14:03:59 +0000
commit1e1e5b8d98750a162335f64ec3c792ce80c9866c (patch)
tree7165916a79824831a6d723fa63e10fbffa87fe06
parent534ddc6166a9031b0c269544929d68f2539ea7a0 (diff)
parent20bb56ebfd4a9d8b21de8f8e75e062ae48d04810 (diff)
downloadrust-1e1e5b8d98750a162335f64ec3c792ce80c9866c.tar.gz
rust-1e1e5b8d98750a162335f64ec3c792ce80c9866c.zip
Auto merge of #103861 - compiler-errors:codegen-select-in-vtable-slot, r=nagisa
Use `codegen_select` in `vtable_trait_upcasting_coercion_new_vptr_slot`

A super tiny clean up
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs24
1 files 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 3417bb87c20..a33534f5747 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -900,25 +900,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) {