Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jplatte opened this issue Feb 25, 2023 · 3 comments
Labels
A-async-await Area: Async & Await A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Feb 25, 2023

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

@jplatte jplatte added the C-bug Category: This is a bug. label Feb 25, 2023
@rustbot rustbot added A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2023
@clubby789
Copy link
Contributor

clubby789 commented Feb 25, 2023

This is explicitly allowed, and the feature is being stabilized soon #107378

// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
// regular fns.

@jplatte
Copy link
Contributor Author

jplatte commented Feb 25, 2023

That comment says "used to be allowed in async fns and forbidden in regular fns" though?

@fmease fmease added the A-async-await Area: Async & Await label Apr 24, 2024
@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged +T-lang

We discussed this in async triage. This is pending action from lang, and we've renominated #107378.

@rustbot rustbot added AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants