File tree 2 files changed +34
-6
lines changed
compiler/rustc_trait_selection/src/traits
2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -154,18 +154,17 @@ fn prepare_vtable_segments_inner<'tcx, T>(
154
154
155
155
// emit innermost item, move to next sibling and stop there if possible, otherwise jump to outer level.
156
156
while let Some ( ( inner_most_trait_ref, emit_vptr, mut siblings) ) = stack. pop ( ) {
157
+ let has_entries =
158
+ has_own_existential_vtable_entries ( tcx, inner_most_trait_ref. def_id ( ) ) ;
159
+
157
160
segment_visitor ( VtblSegment :: TraitOwnEntries {
158
161
trait_ref : inner_most_trait_ref,
159
- emit_vptr : emit_vptr && !tcx. sess . opts . unstable_opts . no_trait_vptr ,
162
+ emit_vptr : emit_vptr && has_entries && !tcx. sess . opts . unstable_opts . no_trait_vptr ,
160
163
} ) ?;
161
164
162
165
// If we've emitted (fed to `segment_visitor`) a trait that has methods present in the vtable,
163
166
// we'll need to emit vptrs from now on.
164
- if !emit_vptr_on_new_entry
165
- && has_own_existential_vtable_entries ( tcx, inner_most_trait_ref. def_id ( ) )
166
- {
167
- emit_vptr_on_new_entry = true ;
168
- }
167
+ emit_vptr_on_new_entry |= has_entries;
169
168
170
169
if let Some ( next_inner_most_trait_ref) =
171
170
siblings. find ( |& sibling| visited. insert ( sibling. upcast ( tcx) ) )
Original file line number Diff line number Diff line change
1
+ //@ run-pass
2
+ //
3
+ // issue: <https://github.com/rust-lang/rust/issues/131813>
4
+
5
+ #![ feature( trait_upcasting) ]
6
+
7
+ trait Pollable {
8
+ #[ allow( unused) ]
9
+ fn poll ( & self ) { }
10
+ }
11
+ trait FileIo : Pollable + Send + Sync {
12
+ fn read ( & self ) { }
13
+ }
14
+ trait Terminal : Send + Sync + FileIo { }
15
+
16
+ struct A ;
17
+
18
+ impl Pollable for A { }
19
+ impl FileIo for A { }
20
+ impl Terminal for A { }
21
+
22
+ fn main ( ) {
23
+ let a = A ;
24
+
25
+ let b = & a as & dyn Terminal ;
26
+ let c = b as & dyn FileIo ;
27
+
28
+ c. read ( ) ;
29
+ }
You can’t perform that action at this time.
0 commit comments