-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemF-trait_upcasting`#![feature(trait_upcasting)]``#![feature(trait_upcasting)]`
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
// Other than the left-most path, vptr should be emitted for each trait. | |
emit_vptr_on_new_entry = true; |
(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)
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemF-trait_upcasting`#![feature(trait_upcasting)]``#![feature(trait_upcasting)]`