Skip to content

Mismatched types issue with GATs #87429

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

Closed
cynecx opened this issue Jul 24, 2021 · 3 comments · Fixed by #87900
Closed

Mismatched types issue with GATs #87429

cynecx opened this issue Jul 24, 2021 · 3 comments · Fixed by #87900
Labels
A-GATs Area: Generic associated types (GATs) F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cynecx
Copy link
Contributor

cynecx commented Jul 24, 2021

I kind of expected this to work:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=95574c86f67ea4cd5b7c3509a9549f6d

#![feature(generic_associated_types)]

use std::fmt::Debug;

trait Family {
    type Member<'a>:
        'a +
        Debug +
        for<'b> PartialEq<Self::Member<'b>>;
    
}

struct I32;

impl Family for I32 {
    type Member<'a> = i32;
}

struct StrRef;

impl Family for StrRef {
    type Member<'a> = &'a str;
}

fn check<'a, 'b, F: Family>(a: F::Member<'a>, b: F::Member<'b>) {
    assert_eq!(a, b);
}

fn main() {
    check::<I32>(0, 0);
}

However it fails with:

error[E0308]: mismatched types
  --> src/main.rs:17:5
   |
17 |     type Member<'a> = i32;
   |     ^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected associated type `<I32 as Family>::Member<'a>`
              found associated type `<I32 as Family>::Member<'b>`

error[E0308]: mismatched types
  --> src/main.rs:23:5
   |
23 |     type Member<'a> = &'a str;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected associated type `<StrRef as Family>::Member<'a>`
              found associated type `<StrRef as Family>::Member<'b>`

For more information about this error, try `rustc --explain E0308`.

cc @jackh726

EDIT: I am not 100% sure but this may has to do with the variance of the gat.

@LeSeulArtichaut LeSeulArtichaut added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 24, 2021
@jackh726
Copy link
Member

@cynecx
Copy link
Contributor Author

cynecx commented Jul 28, 2021

@jackh726 Do you know if this is something that should actually work or is this something that isn't supposed to work?

@jackh726
Copy link
Member

I'm not 100% sure. Using PartialEq<Self::Member<'a>> works

@bors bors closed this as completed in b5fe3bc Aug 24, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants