Skip to content

Anonymous lifetimes in impl trait are allowed in async fn, despite being an unstable feature #108468

Open
@jplatte

Description

@jplatte

I tried this code (playground):

async fn test(args: impl Iterator<Item = &str>) {}

I expected to see this happen: an error because &str contains an anonymous lifetime, and is part of an impl Trait type.

Instead, this happened: Compiles successfully.

Removing async from the function definition gives the following error (on nightly to see the feature gate):

error[E0658]: anonymous lifetimes in `impl Trait` are unstable
 --> src/lib.rs:1:37
  |
1 | fn test(args: impl Iterator<Item = &str>) {}
  |                                     ^ expected named lifetime parameter
  |
  = help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
help: consider introducing a named lifetime parameter
  |
1 | fn test<'a>(args: impl Iterator<Item = &'a str>) {}
  |        ++++                             ++

This feature seems to have no documentation or tracking issue, only an unstable book entry. Given this, and the fact this behavior has been stable on async accidentally (AFAICT) for many releases now, maybe the best solution will be to just un-featuregate this functionality.

Meta

rustc --version --verbose:

rustc 1.67.1 (d5a82bbd2 2023-02-07)

@rustbot label: +A-impl-trait +T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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