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

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

Open
matthewjasper opened this issue Jan 27, 2019 · 1 comment
Open

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

matthewjasper opened this issue Jan 27, 2019 · 1 comment
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@matthewjasper
Copy link
Contributor

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

@matthewjasper matthewjasper added the A-trait-system Area: Trait system label Jan 27, 2019
@jonas-schievink jonas-schievink added A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 9, 2019
@Noratrieb Noratrieb added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Jul 1, 2023
@Noratrieb
Copy link
Member

This errors with

error: implementation of `X` is not general enough
  --> src/lib.rs:19:5
   |
19 |     indirect::<fn(&())>(); // OK
   |     ^^^^^^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
   |
   = note: `X` would have to be implemented for the type `for<'a> fn(&'a ())`
   = note: ...but `X` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`

So I think the issue has been fixed?
I don't see a test in the backlinked PR though.

@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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