reference icon indicating copy to clipboard operation
reference copied to clipboard

Document lifetime elision rules for `impl trait` in return position

Open mheiber opened this issue 3 years ago • 0 comments

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?

mheiber avatar Jan 03 '22 15:01 mheiber