Closed
Description
I tried this code:
#![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_dump_vtable]
trait Marker {}
trait Pencil { fn f(&self) {} }
#[rustc_dump_vtable]
trait Imperfection: Pencil + Marker {}
struct T;
impl Marker for T {}
impl Pencil for T {}
impl Imperfection for T {}
fn main() {
(&T as &dyn Imperfection).f();
let _a = &T as &dyn Marker;
}
I expected Imperfection
to have vtable layout which is DSA, Pencil::f
.
Instead, it also includes vptr(Marker)
. Note that this is unnecessary as Marker
's vtable only contains DSA
triplet and Imperfection
's vtable can be casted to Marker
's. Ideally we should never emit vptr
s to empty traits.
error: vtable entries for `<T as Imperfection>`: [
MetadataDropInPlace,
MetadataSize,
MetadataAlign,
Method(<T as Pencil>::f),
TraitVPtr(<T as Marker>),
]
--> src/main.rs:9:1
|
9 | trait Imperfection: Pencil + Marker {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: vtable entries for `<T as Marker>`: [
MetadataDropInPlace,
MetadataSize,
MetadataAlign,
]
--> src/main.rs:5:1
|
5 | trait Marker {}
| ^^^^^^^^^^^^
This is a continuation of #113840, inspired by #113856 (comment); #113856 missed this case.
Meta
rustc
version:
1.73.0-nightly (2023-08-16 07438b0928c6691d6ee7)