use implied bounds when checking opaque types by aliemjay · Pull Request #106038 · rust-lang/rust (original) (raw)

During opaque type inference, we check for the well-formedness of the hidden type in the opaque type's own environment, not the one of the defining site, which are different in the case of TAIT.

However in the case of associated-type-impl-trait, we don't use implied bounds from the impl header. This caused us to reject the following:

trait Service { type Output; fn call(req: Req) -> Self::Output; }

impl<'a, Req> Service<&'a Req> for u8 { type Output= impl Sized; // we can't prove WF of hidden type WF(&'a Req) although it's implied by the impl //~^ ERROR type parameter Req doesn't live long enough fn call(req: &'a Req) -> Self::Output { req } }

although adding an explicit bound would make it pass:

I believe it should pass as we already allow the concrete type to be used:

impl<'a, Req> Service<&'a Req> for u8 {

Fixes #95922

Builds on #105982

cc @lcnr (because implied bounds)

r? @oli-obk