trait Foo {} impl<'a, T: Foo> Foo for &'a T {} impl Foo for Box {} struct Iter<'a, T> { current: Option>, remaining: T, } impl<'a, T> Iterator for Iter<'a, T> where T: Iterator, T::Item: Foo + 'a, { type Item = Box; fn next(&mut self) -> Option { let result = self.current.take(); self.current = Box::new(self.remaining.next()).map(|f| Box::new(f) as _); result } } struct Bar(Vec>); impl Bar { fn iter(&self) -> impl Iterator> { Iter { //~^ ERROR lifetime may not live long enough current: None, remaining: self.0.iter(), } } } struct Baz(Vec>); impl Baz { fn iter(&self) -> impl Iterator> + '_ { Iter { //~^ ERROR lifetime may not live long enough current: None, remaining: self.0.iter(), } } } struct Bat(Vec>); impl Bat { fn iter<'a>(&'a self) -> impl Iterator> + 'a { Iter { //~^ ERROR lifetime may not live long enough current: None, remaining: self.0.iter(), } } } struct Ban(Vec>); impl Ban { fn iter<'a>(&'a self) -> impl Iterator> { Iter { //~^ ERROR lifetime may not live long enough current: None, remaining: self.0.iter(), } } } fn main() {}