about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-10 04:36:11 +0000
committerMichael Goulet <michael@errs.io>2025-01-30 15:33:58 +0000
commitfdc4bd22b7b8117f4a3864c342773df600f5b956 (patch)
tree404a8293a3401144634e980e436c1b7ca1faac18 /compiler/rustc_codegen_ssa/src
parent37a430e6ea0a674287b53a017497b3414e44b93d (diff)
downloadrust-fdc4bd22b7b8117f4a3864c342773df600f5b956.tar.gz
rust-fdc4bd22b7b8117f4a3864c342773df600f5b956.zip
Do not treat vtable supertraits as distinct when bound with different bound vars
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/meth.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_ssa/src/meth.rs b/compiler/rustc_codegen_ssa/src/meth.rs
index 64cd4c38937..c51a57be71c 100644
--- a/compiler/rustc_codegen_ssa/src/meth.rs
+++ b/compiler/rustc_codegen_ssa/src/meth.rs
@@ -96,24 +96,28 @@ fn dyn_trait_in_self(ty: Ty<'_>) -> Option<ty::PolyExistentialTraitRef<'_>> {
 pub(crate) fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
     cx: &Cx,
     ty: Ty<'tcx>,
-    trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
+    poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
 ) -> Cx::Value {
     let tcx = cx.tcx();
 
     // Check the cache.
-    if let Some(&val) = cx.vtables().borrow().get(&(ty, trait_ref)) {
+    if let Some(&val) = cx.vtables().borrow().get(&(ty, poly_trait_ref)) {
         return val;
     }
 
+    // FIXME(trait_upcasting): Take a non-higher-ranked vtable as arg.
+    let trait_ref =
+        poly_trait_ref.map(|trait_ref| tcx.instantiate_bound_regions_with_erased(trait_ref));
+
     let vtable_alloc_id = tcx.vtable_allocation((ty, trait_ref));
     let vtable_allocation = tcx.global_alloc(vtable_alloc_id).unwrap_memory();
     let vtable_const = cx.const_data_from_alloc(vtable_allocation);
     let align = cx.data_layout().pointer_align.abi;
     let vtable = cx.static_addr_of(vtable_const, align, Some("vtable"));
 
-    cx.apply_vcall_visibility_metadata(ty, trait_ref, vtable);
-    cx.create_vtable_debuginfo(ty, trait_ref, vtable);
-    cx.vtables().borrow_mut().insert((ty, trait_ref), vtable);
+    cx.apply_vcall_visibility_metadata(ty, poly_trait_ref, vtable);
+    cx.create_vtable_debuginfo(ty, poly_trait_ref, vtable);
+    cx.vtables().borrow_mut().insert((ty, poly_trait_ref), vtable);
     vtable
 }