Skip to content

TAIT bug report from tracking issue #150685

@BoxyUwU

Description

@BoxyUwU

I found what I believe is a bug, that seems to only trigger when using a closure as the associated type of a trait.
The following does not compile:

pub trait Bind {
    type Arg;
    type OutFn;

    fn bind<'a>(self, arg: Self::Arg) -> Self::OutFn
    where
        Self: 'a,
        Self::Arg: 'a,
        Self::OutFn: 'a,
        Self::Arg: Clone;
}

impl<Arg, Out> Bind for fn(Arg) -> Out {
    type Arg = Arg;
    type OutFn = impl Fn() -> Out;

    fn bind<'a>(self, arg: Self::Arg) -> Self::OutFn
    where
        Self: 'a,
        Self::OutFn: 'a,
        Self::Arg: 'a,
        Self::Arg: Clone,
    {
        move || self(arg.clone())
    }
}

The compiler produces the output:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Arg: Clone` is not satisfied
  --> src/main.rs:28:9
   |
28 |         move || self(arg.clone())
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Arg`
   |
note: required by a bound in `<fn(Arg) -> Out as Bind>::bind`
  --> src/main.rs:26:20
   |
21 |     fn bind<'a>(self, arg: Self::Arg) -> Self::OutFn
   |        ---- required by a bound in this associated function
...
26 |         Self::Arg: Clone,
   |                    ^^^^^ required by this bound in `<fn(Arg) -> Out as Bind>::bind`
help: consider restricting type parameter `Arg` with trait `Clone`
   |
17 | impl<Arg: std::clone::Clone, Out> Bind for fn(Arg) -> Out {
   |         +++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3e6d260f4ed442040fabce0bdebc8e9f

Originally posted by @Houtamelo in #63063

cc @software-artificer

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions