Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WaffleLapkin opened this issue Jul 24, 2023 · 1 comment
Closed

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

WaffleLapkin opened this issue Jul 24, 2023 · 1 comment
Assignees
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

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.

@WaffleLapkin WaffleLapkin added A-trait-system Area: Trait system C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` labels Jul 24, 2023
@WaffleLapkin WaffleLapkin self-assigned this Jul 24, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 24, 2023
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 24, 2023
@compiler-errors compiler-errors removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 24, 2023
@WaffleLapkin
Copy link
Member Author

I'm closing this as not planned, since this can't be "fixed". With unsized_params feature method_that_takes_self is actually callable.

@WaffleLapkin WaffleLapkin closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants