Description
openedon Sep 5, 2013
This is a tracking issue for the "inherent associate type" part of "inherent associated items" part of the RFC 195 "associated items"
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Original description
(This code is written in ancient version of Rust, and is not meant to be used directly.)
When developing a type-parametric impl, I found myself writing code somewhat like this:
struct Grammar<T, NT> { ... }
impl<T:Clone,NT:Eq+Hash+Clone+Primable> Grammar<T,NT> {
fn to_nt_map(&self) -> HashMap<NT, ~[Prod<T,NT>]>
{
type Rules = ~[Prod<T,NT>];
type NTMap = HashMap<NT, Rules>;
...
}
fn from_nt_map(start: &NT, rules: &HashMap<NT, ~[Prod<T,NT>]>)
-> Grammar<T,NT>
{
type Rules = ~[Prod<T,NT>];
type NTMap = HashMap<NT, Rules>;
...
}
pub fn eliminate_left_recursion(&self) -> Grammar<T,NT>
{
...
}
...
}
I cannot make a type
definition for HashMap<NT, ~[Prod<T,NT>]>
outside of the impl
because it then those free references to NT
and T
would be unbound.
And I cannot put a type
definition within the impl, even an impl for a struct such as this (it simply does not parse with the current grammar).
(Being able to put type definitions within impls will probably arise naturally from #5033, when we get around to that. But that is nonetheless a separate issue from this: Associated Types (and Associated Items) are about enabling certain patterns for the user of a trait, while this ticket describes a convenience for the implementor of a struct.)
Steps
- Implement the RFC
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
Implementation history
- Add incomplete feature gate for inherent associate types. #82516
- Correctly resolve Inherent Associated Types #103621
- Respect visibility & stability of inherent associated types #104348
- Properly substitute inherent associated types. #105224
- Normalize inherent associated types after substitution #105315
- Detect inherent associated types not having CamelCase #105768
- Type-directed probing for inherent associated types #105961
- Introduce
AliasKind::Inherent
for inherent associated types #109410 - rustdoc: render visibility on associated types #110945
- Pretty-print inherent projections correctly #111486
- Structurally normalize weak and inherent in new solver #114594
- Do not erase late bound regions when selecting inherent associated types #118118
- Relate Inherent Associated Types using eq #118262