rust-lang / rust-lang/reference
Document lifetime elision rules for `impl trait` in return position
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
It looks like there is lifetime elision logic for impl trait in return position, but these rules are not documented in the reference iuc:
The following code type-checks, but does not type-check without the explicit placeholder lifetime + '_:
struct Foo(u32);
// does not type-check without the placeholder lifetime
fn example1(foo: &Foo) -> impl Iterator<Item = u32> + '_ {
(0..).map(|n: u32| {
n + foo.0
})
}
Are the rules the same as the lifetime elision rules for trait objects?
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 reading the linked RFC and the Reference's lifetime elision rules, then verify the provided impl Iterator example with and without + '_. Document the applicable lifetime-elision rules for impl Trait in return position and clarify whether they match trait-object rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100