Skip to content

anonymous lifetimes in impl Trait are unstable *except in async* #149076

@ijackson

Description

@ijackson

Code

pub fn f(
    _: impl Iterator<Item=&str>,
) {}

Current output

error[E0658]: anonymous lifetimes in `impl Trait` are unstable
 --> src/lib.rs:2:28
  |
2 |     _: impl Iterator<Item=&str>,
  |                            ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 ~ pub fn f<'a>(
2 ~     _: impl Iterator<Item=&'a str>,
  |

Desired output

error[E0658]: anonymous lifetimes in `impl Trait` are unstable
 --> src/lib.rs:2:28
  |
2 |     _: impl Iterator<Item=&str>,
  |                            ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 ~ pub fn f<'a>(
2 ~     _: impl Iterator<Item=&'a str>,
  |
help: note that this is allowed in async fn, due to a ??bug or something??
see ticket https://github.com/rust-lang/rust/issues/108468

Rationale and extra context

I was just refactoring some code and broke out a sync function from an async one, with many of the same arguments. The compiler tells me that the anonymous lifetimes aren't allowed - but of course they were.

Other cases

This one compiles.

pub async fn f(
    _: impl Iterator<Item=&str>,
) {}

Rust Version

Today's playground, stable.

Anything else?

This anomaly has persisted for two and a half years. Presumably it's not going to be fixed soon.

In the meantime, we could avoid gaslighting the poor user..

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsI-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-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