Skip to content

vtables may be include auto traits #131820

Closed
@lcnr

Description

@lcnr
Contributor

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 17, 2024
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)
T-typesRelevant to the types team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 17, 2024
WaffleLapkin

WaffleLapkin commented on Oct 17, 2024

@WaffleLapkin
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-dyn-traitArea: trait objects, vtable layoutC-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.T-typesRelevant to the types 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

        Participants

        @fmease@lcnr@WaffleLapkin@rustbot

        Issue actions

          vtables may be include auto traits · Issue #131820 · rust-lang/rust