Skip to content

[Universes] Indirection allows calling of invalid trait method #57936

Open
@matthewjasper

Description

@matthewjasper

The following code has different behaviour depending on whether the associated function is called directly or through a method call. For example:

trait X {
    type G;
    fn make_g() -> Self::G;
}

impl<'a> X for fn(&'a ()) {
    type G = &'a ();

    fn make_g() -> Self::G {
        &()
    }
}

fn indirect<T: X>() {
    let x = T::make_g();
}

fn call_indirect() {
    indirect::<fn(&())>(); // OK
}

fn direct() {
    let x = <fn(&())>::make_g(); //~ ERROR
}

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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

    Issue actions