Skip to content

Prove closure bound for TAIT, lifetime bound not satisfied #100267

Closed

Description

I tried this code:

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

use std::future::Future;

pub trait Service<Cx, Request> {
    type Response;
    type Future<'cx>: Future<Output = Self::Response> + Send + 'cx
    where
        Cx: 'cx,
        Self: 'cx;

    fn call<'cx, 's>(&'s mut self, cx: &'cx mut Cx, req: Request) -> Self::Future<'cx>
    where
        's: 'cx;
}

pub struct Test<S>(S);

impl<Cx, Req, S> Service<Cx, Req> for Test<S>
where
    Req: Send + 'static,
    S: Service<Cx, Req> + Send + 'static,
    Cx: Send + 'static,
{
    type Response = S::Response;

    type Future<'cx> = impl Send + Future<Output = Self::Response> + 'cx
    where
        Cx: 'cx,
        Self: 'cx;

    fn call<'cx, 's>(&'s mut self, cx: &'cx mut Cx, req: Req) -> Self::Future<'cx>
    where
        's: 'cx,
    {
        async move { self.0.call(cx, req).await }
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (d394408fb 2022-08-07)
binary: rustc
commit-hash: d394408fb38c4de61f765a3ed5189d2731a1da91
commit-date: 2022-08-07
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 14.0.6
Backtrace

 Compiling rust_prove_closure_bug v0.1.0 (/Users/yifei/code/rust_prove_closure_bug)
error[E0478]: lifetime bound not satisfied
  --> src/main.rs:28:24
   |
28 |     type Future<'cx> = impl Send + Future<Output = Self::Response> + 'cx
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: lifetime parameter instantiated with the empty lifetime
note: but lifetime parameter must outlive the lifetime `'cx` as defined here
  --> src/main.rs:28:17
   |
28 |     type Future<'cx> = impl Send + Future<Output = Self::Response> + 'cx
   |                 ^^^

For more information about this error, try `rustc --explain E0478`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions