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

Ambiguous associated type. #75896

Closed
Kesanov opened this issue Aug 25, 2020 · 1 comment
Closed

Ambiguous associated type. #75896

Kesanov opened this issue Aug 25, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@Kesanov
Copy link

Kesanov commented Aug 25, 2020

I tried this code:

use std::fmt::Debug;

pub mod a {
    pub type A = ();
    pub mod b {
        pub type B = ();
    }
}

fn build() {
    let a: a::A     = unimplemented!();
    let b: a::b::B  = unimplemented!(); 
    

    println!("{:?} {:?}", a, b);
}

// the same code as above, just implemented with traits

trait ModA {
    type A: Debug;
    type B: ModB;
}
trait ModB {
    type B: Debug;
}

fn build2<A:ModA>() {
    let a: A::A     = unimplemented!(); // works just fine
    let b: A::B::B  = unimplemented!(); // fails to compile

    println!("{:?} {:?}", a, b)
}

I expected to compile it without errors.

Instead, this happened:

error[E0223]: ambiguous associated type
  --> src/main.rs:28:12
   |
28 |     let b: A::B::B  = unimplemented!(); // fails to compile
   |            ^^^^^^^ help: use fully-qualified syntax: `<<A as ModA>::B as Trait>::B`

E0223 states:

The problem here is that we're attempting to take the type of X from MyTrait. Unfortunately, the type of X is not defined, because it's only made concrete in implementations of the trait.

This obviously doesn't apply here - B is as concrete as A. And the type A::B::B is just as specific as A::A and A::B, yet only the former fails to compile!

@Kesanov Kesanov added the C-bug Category: This is a bug. label Aug 25, 2020
@jonas-schievink
Copy link
Contributor

Caused by #22519, so closing in favor of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants