Why is there a difference regarding lifetime elision of impl trait function arguments between async and non-async functions?

Viewed 200

This code compiles:

async fn foo(_: impl Iterator<Item = &u32>) {}

However, removing the async, it does not work anymore:

fn foo(_: impl Iterator<Item = &u32>) {}

Instead, it results in:

error[E0106]: missing lifetime specifier
 --> src/lib.rs:1:32
  |
1 | fn foo(_: impl Iterator<Item = &u32>) {}
  |                                ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 | fn foo<'a>(_: impl Iterator<Item = &'a u32>) {}
  |       ^^^^                         ^^^

(Playground)

Why is there a difference regarding lifetime elision between async and non-async functions? This makes no sense to me. It seems like the non-async case could easily leave out the lifetime as well. It's just introducing another anonymous input lifetime.

0 Answers
Related