Consider the following code:
struct Foo;
trait Bar {
const CONST: usize;
type Ty;
}
impl Bar for Foo {
const CONST: usize = 10;
type Ty = String;
}
We can get the CONST
of Foo
by writing Foo::CONST
, omitting the <Foo as Bar>
.
However, we must write <Foo as Bar>::Ty
to refer to the associated type.
error[E0223]: ambiguous associated type
--> src/main.rs:17:51
|
17 | assert_eq!(type_name::<String>(), type_name::<Foo::Ty>());
| ^^^^^^^ help: use fully-qualified syntax: `<Foo as Bar>::Ty`
For more information about this error, try `rustc --explain E0223`.
The official documentation says that it's "due to internal limitations" without any roadmaps or something else.
I'd like to know what specifically is preventing this kind of code, and if any of these obstacles are currently being attempted to be addressed? I'm writing some web api wrappers, and being able to get associative types directly would improve the organization and experience of my codebase.