Open
Description
I tried this code: (playground)
#![feature(generic_associated_types)]
use std::marker::PhantomData;
trait AsyncFn<Arg> { type Output; }
trait RequestFamily { type Type<'a>; }
trait Service {}
struct MyFn;
impl AsyncFn<String> for MyFn { type Output = (); }
impl RequestFamily for String { type Type<'a> = String; }
struct ServiceFromAsyncFn<F, Req>(F, PhantomData<Req>);
impl<F, Req, O> Service for ServiceFromAsyncFn<F, Req>
where
Req: RequestFamily,
F: AsyncFn<Req>,
F: for<'a> AsyncFn<Req::Type<'a>, Output = O>,
{
}
fn assert_service() -> impl Service {
ServiceFromAsyncFn(MyFn, PhantomData)
}
It fails type inference with the following error:
error[E0282]: type annotations needed
--> src/lib.rs:23:24
|
23 | fn assert_service() -> impl Service {
| ^^^^^^^^^^^^ cannot infer type for type parameter `O`
This is super weird because type paramters that don't appear in Self
type of the impl are not expected to fail inference.
Surprisingly, removing O
makes it pass:
-impl<F, Req, O> Service for ServiceFromAsyncFn<F, Req>
+impl<F, Req> Service for ServiceFromAsyncFn<F, Req>
where
Req: RequestFamily,
F: AsyncFn<Req>,
- F: for<'a> AsyncFn<Req::Type<'a>, Output = O>,
+ F: for<'a> AsyncFn<Req::Type<'a>>,
Meta
Nightly version: 1.62.0-nightly
(2022-05-03 e1b71fe)
@rustbot label F-generic_associated_types T-compiler A-traits A-inference A-lifetimes
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Type inferenceArea: Lifetimes / regionsArea: Trait systemRelevant to the compiler team, which will review and decide on the PR/issue.Fixed by the next-generation trait solver, `-Znext-solver`.