Skip to content

Tracking issue for inherent associated types #8995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks
pnkfelix opened this issue Sep 5, 2013 · 32 comments
Open
3 tasks

Tracking issue for inherent associated types #8995

pnkfelix opened this issue Sep 5, 2013 · 32 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-inherent_associated_types `#![feature(inherent_associated_types)]` S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented 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"

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

@emberian

This comment has been minimized.

@emberian

This comment has been minimized.

@pnkfelix

This comment has been minimized.

@emberian

This comment has been minimized.

@huonw

This comment has been minimized.

@emberian

This comment has been minimized.

@pnkfelix

This comment has been minimized.

@reem

This comment has been minimized.

@pnkfelix

This comment has been minimized.

@pnkfelix

This comment has been minimized.

@pnkfelix pnkfelix changed the title RFC: allow type definition item within impl implement inherent associated items (see RFC 59). Oct 6, 2014
@rohel01

This comment has been minimized.

@steveklabnik steveklabnik added A-associated-items Area: Associated items (types, constants & functions) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team and removed A-grammar Area: The grammar of Rust A-type-system Area: Type system P-low Low priority labels Feb 7, 2017
@steveklabnik

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 19, 2017
@Mark-Simulacrum Mark-Simulacrum added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jul 27, 2017
@yodaldevoid

This comment has been minimized.

@tinaun

This comment has been minimized.

@eddyb

This comment has been minimized.

@jhpratt
Copy link
Member

jhpratt commented Feb 26, 2023

I'd just like to say thank you to you three for working on this feature! I know it's not simple, but it's something a lot of people will appreciate when it's eventually completed.

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Mar 24, 2023
=== stdout ===
=== stderr ===
error[E0261]: use of undeclared lifetime name `'d`
  --> /home/runner/work/glacier/glacier/ices/109299.rs:10:21
   |
10 | impl<'cursor> Lexer<'d> {
   |      -              ^^ undeclared lifetime
   |      |
   |      help: consider introducing lifetime `'d` here: `'d,`

error[E0412]: cannot find type `DocCursorImpl` in this scope
  --> /home/runner/work/glacier/glacier/ices/109299.rs:11:23
   |
11 |     type Cursor<'a> = DocCursorImpl<'a>;
   |                       ^^^^^^^^^^^^^ not found in this scope

error[E0658]: inherent associated types are unstable
  --> /home/runner/work/glacier/glacier/ices/109299.rs:11:5
   |
11 |     type Cursor<'a> = DocCursorImpl<'a>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #8995 <rust-lang/rust#8995> for more information
   = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0261, E0412, E0658.
For more information about an error, try `rustc --explain E0261`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue May 9, 2023
=== stdout ===
=== stderr ===
error[E0637]: `&` without an explicit lifetime name cannot be used here
 --> /home/runner/work/glacier/glacier/ices/109071.rs:4:17
  |
4 |     type Item = &[T];
  |                 ^ explicit lifetime name needed here

error[E0601]: `main` function not found in crate `109071`
  --> /home/runner/work/glacier/glacier/ices/109071.rs:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `/home/runner/work/glacier/glacier/ices/109071.rs`

error[E0107]: missing generics for struct `Windows`
 --> /home/runner/work/glacier/glacier/ices/109071.rs:3:9
  |
3 | impl<T> Windows {
  |         ^^^^^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `T`
 --> /home/runner/work/glacier/glacier/ices/109071.rs:1:8
  |
1 | struct Windows<T> {}
  |        ^^^^^^^ -
help: add missing generic argument
  |
3 | impl<T> Windows<T> {
  |                +++

error[E0658]: inherent associated types are unstable
 --> /home/runner/work/glacier/glacier/ices/109071.rs:4:5
  |
4 |     type Item = &[T];
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <rust-lang/rust#8995> for more information
  = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0107, E0601, E0637, E0658.
For more information about an error, try `rustc --explain E0107`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue May 9, 2023
=== stdout ===
=== stderr ===
warning: the feature `inherent_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/109790.rs:1:12
  |
1 | #![feature(inherent_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <rust-lang/rust#8995> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: struct `Foo` is never constructed
 --> /home/runner/work/glacier/glacier/ices/109790.rs:3:8
  |
3 | struct Foo<T>(T);
  |        ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: associated type `Assoc` is never used
 --> /home/runner/work/glacier/glacier/ices/109790.rs:6:10
  |
5 | impl<'a> Foo<fn(&'a ())> {
  | ------------------------ associated type in this implementation
6 |     type Assoc = &'a ();
  |          ^^^^^

warning: function `bar` is never used
  --> /home/runner/work/glacier/glacier/ices/109790.rs:12:4
   |
12 | fn bar(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {}
   |    ^^^

warning: 4 warnings emitted

==============
@Cypher1
Copy link

Cypher1 commented May 30, 2023

This seems particularly important for resolving 'clippy::type_complexity' when using large types inside parameterized types with multiple arguments.

Normally we'd use a type Foo = Bar<A, B, C>; but in a generic type, those types may not be accessible except via more type parameters, leading to new complex types.

Keep to hear more about blockers :)

@fmease
Copy link
Member

fmease commented May 30, 2023

Keep to hear more about blockers

The most recent major blocker is fixing #108491 which is not easy it seems. Basically, you cannot use inherent associated types inside of structs, enums, unions or where clauses (as opposed to function bodies, constants and type aliases) and some function signatures without encountering a cycle error first. According to my current understanding this is due to architectural limitations in the compiler (see this semi-related Zulip topic, cc #22519 the equivalent for trait assoc tys).

Since #109410 got merged, I'm investigating approaches to solve this in a proper way without too much rework.

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
…ypes, r=jsha

rustdoc: render visibility on associated types

This should only affect inherent associated types (rust-lang#8995).
bors added a commit to rust-lang/rust-analyzer that referenced this issue Jan 3, 2024
feat: resolve inherent and implemented associated items in docs

This partially fixes #9694.

Supported:
- Trait methods and constants.
  * Due to resolution differences pointed out during the review of the PR, trait associated types are _not_ supported.
- Inherent methods, constants and associated types.
  * Inherent associated types are a [nightly feature](rust-lang/rust#8995), and are supported with no additional work in this PR.

Screenshot of VS Code running with the change:

<img width="513" alt="image" src="https://github.com/rust-lang/rust-analyzer/assets/7189784/c37ed8b7-b572-4684-8e81-2a817b0027c4">

You can see that the items are resolved (excl. trait associated types) since they are semantically highlighted in the doc comment.
@fmease fmease changed the title Tracking issue for inherent associated type. Tracking issue for inherent associated types Jan 5, 2024
@fmease fmease added S-tracking-impl-incomplete Status: The implementation is incomplete. and removed S-tracking-unimplemented Status: The feature has not been implemented. labels Feb 21, 2024
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-inherent_associated_types `#![feature(inherent_associated_types)]` S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests