rust-lang / rust-lang/rust

Cannot chain inherent associated types

Open
#122,584 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-inherent_associated_types T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(inherent_associated_types)]
struct A<const N: usize> {}

struct B<const N: usize> {}

impl<const N: usize> B<N> {
    type C_ = C<N>;
}

struct C<const N: usize> {}

impl<const N: usize> A<N> {
    type B_ = B<N>;

    fn fun() -> Self::B_::C_ {
        todo!()
    }
}

fn main() {}

rustc says:

error[E0223]: ambiguous associated type
  --> src/lib.rs:15:17
   |
15 |     fn fun() -> Self::B_::C_ {
   |                 ^^^^^^^^^^^^
   |
help: if there were a trait named `Example` with associated type `C_` implemented for `A<N>::B_`, you could use the fully-qualified path
   |
15 |     fn fun() -> <A<N>::B_ as Example>::C_ {
   |                 ~~~~~~~~~~~~~~~~~~~~~~~~~
Meta

rustc --version --verbose:

rustc 1.78.0-nightly (4a0cc881d 2024-03-11)
binary: rustc
commit-hash: 4a0cc881dcc4d800f10672747f61a94377ff6662
commit-date: 2024-03-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the supplied reproducer with the nightly Rust toolchain and examine resolution of the Self::B_::C_ return type in the A inherent implementation. Done means the chained inherent associated type path resolves without the ambiguous associated type error, with appropriate regression coverage added for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.