Skip to content
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

vtables may be include auto traits #131820

Closed
lcnr opened this issue Oct 17, 2024 · 1 comment
Closed

vtables may be include auto traits #131820

lcnr opened this issue Oct 17, 2024 · 1 comment
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-trait-objects Area: trait objects, vtable layout 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Oct 17, 2024

extracted from #131813

trait Super {
    fn super_method(&self) {}
}
trait WithoutAuto: Super {}
trait WithAutoAfter: Super + Send {}
trait WithAutoBefore: Send + Super {}

impl Super for () {}
impl WithoutAuto for () {}
impl WithAutoAfter for () {}
impl WithAutoBefore for () {}

pub fn main() {
    drop::<&dyn WithoutAuto>(&());
    drop::<&dyn WithAutoAfter>(&());
    drop::<&dyn WithAutoBefore>(&());
}

results in the following assembly:

example::main::h981403045b91afa3:
        push    rax
        mov     edi, 1
        lea     rsi, [rip + .L__unnamed_1]
        call    qword ptr [rip + core::mem::drop::hc9ab6a5c0d43ca28@GOTPCREL]
        mov     edi, 1
        lea     rsi, [rip + .L__unnamed_2]
        call    qword ptr [rip + core::mem::drop::ha5195050a20993aa@GOTPCREL]
        mov     edi, 1
        lea     rsi, [rip + .L__unnamed_1]
        call    qword ptr [rip + core::mem::drop::h1632a30342c576a4@GOTPCREL]
        pop     rax
        ret

.L__unnamed_1:
        .asciz  "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000"
        .quad   example::Super::super_method::h936b862074aa3dae

.L__unnamed_3:
        .asciz  "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000"

.L__unnamed_2:
        .asciz  "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000"
        .quad   example::Super::super_method::h936b862074aa3dae
        .quad   .L__unnamed_3

https://rust.godbolt.org/z/Yef9xdjfP

This looks like the vtable for WithAutoAfter - but not for WithAutoBefore - includes a slot for Send. Given that Send is an auto-trait this seems very unexpected to me

@lcnr lcnr added the C-bug Category: This is a bug. label Oct 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 17, 2024
@lcnr lcnr added the A-trait-objects Area: trait objects, vtable layout label Oct 17, 2024
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 17, 2024
@WaffleLapkin WaffleLapkin added the F-trait_upcasting `#![feature(trait_upcasting)]` label Oct 17, 2024
@WaffleLapkin
Copy link
Member

I think this is a dupe of #114942. We should never emit a vptr for traits without own vtable entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-trait-objects Area: trait objects, vtable layout 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. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants