about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits/vtable.rs
diff options
context:
space:
mode:
authorZachary S <zasample18+github@gmail.com>2025-08-23 20:48:44 -0500
committerZachary S <zasample18+github@gmail.com>2025-08-25 16:14:15 -0500
commit904e83c53fece4a34c2e90bb44e362d8868d65f3 (patch)
tree5060a43d2ed2ea45fe7ba87d5758c9f471f7f57c /compiler/rustc_trait_selection/src/traits/vtable.rs
parentc5a6a7bdd89f099544fa0d3fad4d833d238377ad (diff)
downloadrust-904e83c53fece4a34c2e90bb44e362d8868d65f3.tar.gz
rust-904e83c53fece4a34c2e90bb44e362d8868d65f3.zip
Only consider auto traits empty for the purposes of omitting vptrs from subtrait vtables
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/vtable.rs')
-rw-r--r--compiler/rustc_trait_selection/src/traits/vtable.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs
index 3565c11249a..7e8a41457d4 100644
--- a/compiler/rustc_trait_selection/src/traits/vtable.rs
+++ b/compiler/rustc_trait_selection/src/traits/vtable.rs
@@ -153,7 +153,12 @@ fn prepare_vtable_segments_inner<'tcx, T>(
 
         // emit innermost item, move to next sibling and stop there if possible, otherwise jump to outer level.
         while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() {
-            let has_entries = has_own_existential_vtable_entries(tcx, inner_most_trait_ref.def_id);
+            // We don't need to emit a vptr for "truly-empty" supertraits, but we *do* need to emit a
+            // vptr for supertraits that have no methods, but that themselves have supertraits
+            // with methods, so we check if any transitive supertrait has entries here (this includes
+            // the trait itself).
+            let has_entries = ty::elaborate::supertrait_def_ids(tcx, inner_most_trait_ref.def_id)
+                .any(|def_id| has_own_existential_vtable_entries(tcx, def_id));
 
             segment_visitor(VtblSegment::TraitOwnEntries {
                 trait_ref: inner_most_trait_ref,