I can answer the first question, I don’t know if I can provide all the details for the second.
For starters:
The trait sub
inherits assoc
's associated item because anything implementing sub
has to implement assoc
, and thus has to provide some type X
to associated with it.
The second bit:
The problem you are running into, in a simpler snippet, is this being not allowed:
trait TheTrait { type Assoc; }
type Alias = TheTrait;
I believe this is due to Alias
the not including all of the information. See this bigger example:
trait TheTrait {
type Assoc;
fn get_assoc(&self) -> Self::Assoc;
}
type Alias = TheTrait;
fn uses_alias(thing: &Alias) {
let x = thing.get_assoc();
// what type is `x`...? How can we know?
}
Like the comment suggests, when using Alias
like that, there is no way to know what the associated type is.
To fix this, we need to either specify a specific associated type for the alias:
type Alias = TheTrait<Assoc=i32>;
Or specify that alias is generic for a T and specifies the associated type is that T:
type Alias<T> = TheTrait<Assoc=T>
With these, uses_alias
can safely either know that get_assoc
returns an i32
, or specify another bound over T
to know what it gets.