Skip to content

VTables include uncallable methods (that take self by value) #114007

Closed as not planned
@WaffleLapkin

Description

@WaffleLapkin

I expected that given the following method, both methods won't be included in the vtable (note that this trait is object safe, self "implies" where Self: Sized for object safety check)

trait Tr {
    fn method_that_takes_self(self);
    fn method_that_takes_self2(self) where Self: Sized {}
}

But, in reality, with 1.73.0-nightly (2023-07-23 8771282d4e7a5c4569e4), method_that_takes_self is included in the vtable, even though you can't call it:

vtable entries for `<String as Tr>`: [
    MetadataDropInPlace,
    MetadataSize,
    MetadataAlign,
    Method(<String as Tr>::method_that_takes_self - shim(vtable)),
]

This is especially sub-optimal in the presence of trait upcasting, since this makes otherwise empty (wrt to trait objects) traits non-empty, adding need for more vptrs.

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-trait_upcasting`#![feature(trait_upcasting)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions