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;
}
(play)
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 vptrs 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)
I tried this code:
(play)
I expected
Imperfectionto have vtable layout which isDSA, Pencil::f.Instead, it also includes
vptr(Marker). Note that this is unnecessary asMarker's vtable only containsDSAtriplet andImperfection's vtable can be casted toMarker's. Ideally we should never emitvptrs to empty traits.This is a continuation of #113840, inspired by #113856 (comment); #113856 missed this case.
Meta
rustcversion: