rust-lang / rust-lang/rust

Better type inference with `impl_trait_in_assoc_type` (ITIAT)

Open
#130,910 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

D-confusing F-impl_trait_in_assoc_type
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#![feature(impl_trait_in_assoc_type)]

fn coca(_: String) {}

trait Foo<T> {}
impl Foo<()> for String {}

trait Bar {
    type T;
    type I: Foo<Self::T>;
    type F: FnOnce(Self::I);

    const M: Self::F;
}

impl Bar for () {
    type T = impl Sized; // The compiler could infer this associated type as `()`.
    type I = impl Foo<Self::T>;
    type F = impl FnOnce(Self::I);

    const M: Self::F = coca;
}

playground

Errors with:

error[E0277]: the trait bound `String: Foo<<() as Bar>::T>` is not satisfied
  --> src/lib.rs:21:24
   |
21 |     const M: Self::F = coca;
   |                        ^^^^ the trait `Foo<<() as Bar>::T>` is not implemented for `String`
   |
   = help: the trait `Foo<()>` is implemented for `String`

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

Reproduce the Rust nightly example from the issue in the linked Playground and inspect the reported E0277 diagnostic. The desired result is for the compiler to infer the associated type T as (), satisfy Foo<()> for String, and accept the const assignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.