-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.
Description
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!
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.