Skip to content

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

Description

@LYF1999

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`.

Activity

  1. LYF1999 commented on Aug 8, 2022

    @LYF1999
    ContributorAuthor

    I found this error occurred by this commit caee496 through cargo-bisect-rustc

  2. compiler-errors commented on Aug 8, 2022

    @compiler-errors
    Contributor

    Probably #98835 cc @aliemjay

  3. aliemjay commented on Aug 8, 2022

    @aliemjay
    Contributor

    Minimized:

    #![feature(type_alias_impl_trait)]
    
    type Fut<'a> = impl Sized;
    
    fn call<'cx, 's>() -> Fut<'cx>
    where
        's: 'cx,
    {
        || {}
    }

    @rustbot claim
    @rustbot label F-type_alias_impl_trait T-compiler

  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 8, 2022
  5. PureWhiteWu commented on Aug 23, 2022

    @PureWhiteWu

    This has caused crate volo and motore docs fail to build.
    https://docs.rs/crate/volo/latest
    https://docs.rs/crate/motore/latest

  6. moved this from Todo to Can do after stabilization in type alias impl trait stabilizationon Sep 9, 2022
  7. yshui commented on Sep 17, 2022

    @yshui
    Contributor

    This just upgraded from bad diagnostics to ICE on latest nightly.

  8. added 2 commits that reference this issue on Oct 13, 2022
    7131984
    059bbf7
  9. Repository owner moved this from Can do after stabilization to Done in type alias impl trait stabilizationon Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions