Skip to content

Tracking issue for inherent associated types #8995

Open

Description

@pnkfelix

This is a tracking issue for the "inherent associate type" part of "inherent associated items" part of the RFC 195 "associated items"

Original description for historic preservation

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.)

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.

Steps

Unresolved Questions

None

Implementation history

Activity

  1. emberian commented on Dec 30, 2013

    @emberian
  2. emberian commented on Dec 30, 2013

    @emberian
  3. pnkfelix commented on Dec 31, 2013

    @pnkfelix
    Author
  4. emberian commented on Dec 31, 2013

    @emberian
  5. huonw commented on Dec 31, 2013

    @huonw
  6. emberian commented on Dec 31, 2013

    @emberian
  7. pnkfelix commented on Jan 9, 2014

    @pnkfelix
    Author
  8. reem commented on Sep 15, 2014

    @reem
  9. pnkfelix commented on Oct 6, 2014

    @pnkfelix
    Author
  10. pnkfelix commented on Oct 6, 2014

    @pnkfelix
    Author
  11. changed the title [-]RFC: allow type definition item within impl[/-] [+]implement inherent associated items (see RFC 59).[/+] on Oct 6, 2014
  12. rohel01 commented on Aug 14, 2015

    @rohel01
  13. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.
    T-langRelevant to the language team
    on Feb 7, 2017
  14. 60 remaining items

  15. added 2 commits that reference this issue on Sep 1, 2026
  16. added 8 commits that reference this issue on Sep 1, 2026
  17. added a commit that references this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-inherent_associated_types`#![feature(inherent_associated_types)]`S-tracking-impl-incompleteStatus: The implementation is incomplete.T-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions