Skip to content

Is this difference in lifetime elision for impl Trait arguments between async and non-async function intended? #85417

Open
@LukasKalbertodt

Description

@LukasKalbertodt

This compiles:

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

But this doesn't:

fn foo(_: impl Iterator<Item = &u32>) {}
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>) {}
  |       ^^^^                         ^^^

This difference strikes me as very odd. Is this intended? If so, why?

This is formulated as a question, but if I had to guess, I would classify this as oversight or bug -- that's why I created an issue instead of askig in the forum.

(originally asked here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.

    Type

    No type

    Projects

    Status

    On deck

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions