Skip to content

Asssociated type declared in where clause is not enforced in type parameter #116864

Closed
@c410-f3r

Description

@c410-f3r

For some reason FnMutFut<&'any BAZ::Param, ()> is not being inferred as FnMutFut<&'any i32, ()>, which results in an unsatisfied trait bound error.

use std::future::Future;

pub trait Baz {
    type Param;
}

pub trait FnMutFut<P, R>: FnMut(P) -> Self::Future {
    type Future: Future<Output = R>;
}

impl<P, F, FUT, R> FnMutFut<P, R> for F
where
    F: FnMut(P) -> FUT,
    FUT: Future<Output = R>,
{
    type Future = FUT;
}

pub async fn does_not_work<BAZ>(_: BAZ, mut cb: impl for<'any> FnMutFut<&'any BAZ::Param, ()>)
where
    BAZ: Baz<Param = i32>,
{
    cb(&1i32).await;
}

Perhaps something involving the generic implementation of FnMutFut? Perhaps something involving impl trait?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions