Skip to content

Better type inference with impl_trait_in_assoc_type (ITIAT) #130910

@cynecx

Description

@cynecx
Contributor
#![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`

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 27, 2024
compiler-errors

compiler-errors commented on Sep 27, 2024

@compiler-errors
Member

Using the "single impl rule" to do TAIT inference seems like a bad strategy to commit inference to, I fear.

added
requires-nightlyThis issue requires a nightly compiler in some way.
D-confusingDiagnostics: Confusing error or lint that should be reworked.
on Sep 27, 2024
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Nov 9, 2024
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

    D-confusingDiagnostics: Confusing error or lint that should be reworked.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @compiler-errors@cynecx@lolbinarycat@rustbot@Noratrieb

        Issue actions

          Better type inference with `impl_trait_in_assoc_type` (ITIAT) · Issue #130910 · rust-lang/rust