Skip to content

Type mismatch between associated type and concrete type which are the same type. #34430

Description

@canndrew

Trying to build the following code:

trait WithLifetime<'a> {
    type Type;
}

struct Foo;

enum FooRef {}

impl<'a> WithLifetime<'a> for FooRef {
    type Type = &'a Foo;
}

fn wub<T, F>(f: F)
    where T: for<'a> WithLifetime<'a>,
          F: for<'a> FnOnce(&'a Foo) -> <T as WithLifetime<'a>>::Type
{
}

fn main() {
    wub::<FooRef, _>(|foo| foo)
}

Gives the error:

foo.rs:20:28: 20:31 error: mismatched types:
 expected `<FooRef as WithLifetime<'a>>::Type`,
    found `&'a Foo`
(expected associated type,
    found &-ptr) [E0308]
foo.rs:20     wub::<FooRef, _>(|foo| foo)
                                     ^~~

However <FooRef as WithLifetime<'a>>::Type and &'a Foo are the same type. And the compiler should be able to see that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.E-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