2019.02.26 — impl discussion notes
Handy links:

“lifetime issues”


  •  async fn should support multiple lifetimes #56238 
  •  `async fn` doesn't capture lifetimes of type parameters if other lifetimes are present #55324 
  •  async fn: 'static lifetime not inferred for Arc trait object #54974 

async fn foo<T>()

async fn foo<'a, T>(x: &'a u8) {}

fn foo<'a, T>(x: &'a u8) -> impl Future<Output = ()> + 'a {}



  • current behavior:
  • look for all the lifetimes that appear in the AST
  • if exactly one, we add it as a lifetime bound on the impl Future

fn foo<'async, 'a, T>(x: &'a u8) -> impl Future<Output = ()> + 'async
where 'a: 'async, T: 'async
{ }

// but the "defining scope" of the `Foo` is the fn itself
existential type Foo<'a, T>: Future<Output = ()>;
fn foo<'a, T>(x: &'a u8) -> Foo<'a, T> {..}

async fn foo<T>(x: &u8, y: &u8) -> ()

existential type Foo<'a, 'b, T>: Future<Output = ()>;
fn foo<'a, 'b, T>(x: &'a u8, y: &'b u8) -> Foo<'a, 'b, T>

fn foo(x: Box<dyn Write {+ 'static}>)

side bar: lifetimes in lowering omg


impl Foo for &u8 
// lower to a implicit, early-bound parameter on the impl

fn foo(x: &u8)
// lower to a late-bound parameter on the fn

impl Foo for &u8 { } =>
  impl<'a> Foo for &'a u8
impl Foo for &Box<dyn Write> { } =>
  impl<'a> Foo for &'a Box<dyn Write + 'static>

vague plan: