Closed
Description
While working on #112355 I think I found a bug. Given this program:
#![feature(rustc_attrs)]
#[rustc_dump_vtable]
pub trait What: Send + Sync {
fn a(&self) {}
}
impl What for () {}
fn main() {
(&() as &dyn What).a();
}
rustc outputs the following vtable layout:
[
MetadataDropInPlace,
MetadataSize,
MetadataAlign,
TraitVPtr(<() as Sync>),
Method(<() as What>::a),
]
Which is surprising, because TraitVPtr(<() as Sync>)
is unnecessary — Send
does not have any methods, so Sync
vtable can be inlined...
I think we should be smarter here:
rust/compiler/rustc_trait_selection/src/traits/vtable.rs
Lines 143 to 144 in cb882fa
(for the record, I'm pretty sure this happens in practice, I've found this with log::Log
)
Originally posted by @WaffleLapkin in #65991 (comment)