Skip to content

Lifetime in GAT must outlive trait parameters #91036

Closed
@ilslv

Description

@ilslv

Related to #89970

Code

#![feature(generic_associated_types)]

trait T<'ctx> {
    type Fut<'out> 
    where 
        'ctx: 'out, 
        Self: 'out;
    
    fn test<'me, 'out>(&'me self, ctx: &'ctx i32) -> Self::Fut<'out>
    where
        'me: 'out,
        'ctx: 'out;
}

Basically I want to desugar async fn. For this I need to describe Fut GAT that lives the smallest of the 'me and 'ctx, but I get compiler error with requirement that doesn't really make sense to me.

error: Missing required bounds on Fut
 --> src/lib.rs:4:5
  |
4 | /     type Fut<'out> 
5 | |     where 
6 | |         'ctx: 'out, 
7 | |         Self: 'out;
  | |                   ^ help: add the required where clauses: `, 'out: 'ctx`
  | |___________________|
  | 

error: could not compile `playground` due to previous error

'out cant't outlive 'ctx.

Meta

fails on 1.58.0-nightly (2021-11-18 cc946fcd326f7d85d4af) Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsT-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