File tree 3 files changed +34
-12
lines changed
compiler/rustc_trait_selection/src/traits
3 files changed +34
-12
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
+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ error: vtable entries for `<S as B>`: [
14
14
MetadataSize,
15
15
MetadataAlign,
16
16
Method(<S as T>::method),
17
- TraitVPtr(<S as M2>),
18
17
]
19
18
--> $DIR/multiple-markers.rs:24:1
20
19
|
@@ -26,8 +25,6 @@ error: vtable entries for `<S as C>`: [
26
25
MetadataSize,
27
26
MetadataAlign,
28
27
Method(<S as T>::method),
29
- TraitVPtr(<S as M1>),
30
- TraitVPtr(<S as M2>),
31
28
]
32
29
--> $DIR/multiple-markers.rs:27:1
33
30
|
@@ -39,9 +36,6 @@ error: vtable entries for `<S as D>`: [
39
36
MetadataSize,
40
37
MetadataAlign,
41
38
Method(<S as T>::method),
42
- TraitVPtr(<S as M0>),
43
- TraitVPtr(<S as M1>),
44
- TraitVPtr(<S as M2>),
45
39
]
46
40
--> $DIR/multiple-markers.rs:30:1
47
41
|
You can’t perform that action at this time.
0 commit comments