anonymous lifetimes in `impl Trait` are unstable *except in async*
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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..
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the sync and async snippets from the issue in the stable Playground and compare their diagnostics. Then trace the compiler diagnostic path for anonymous lifetimes in impl Trait and its async exception. Done means the sync diagnostic explains the async behavior with the proposed note while preserving the existing lifetime suggestion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100