2020-06-09 15:57:33 -05:00
|
|
|
trait Foo {}
|
|
|
|
impl<'a, T: Foo> Foo for &'a T {}
|
|
|
|
impl<T: Foo + ?Sized> Foo for Box<T> {}
|
|
|
|
|
|
|
|
struct Iter<'a, T> {
|
|
|
|
current: Option<Box<dyn Foo + 'a>>,
|
|
|
|
remaining: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> Iterator for Iter<'a, T>
|
|
|
|
where
|
|
|
|
T: Iterator,
|
|
|
|
T::Item: Foo + 'a,
|
|
|
|
{
|
|
|
|
type Item = Box<dyn Foo + 'a>;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
let result = self.current.take();
|
|
|
|
self.current = Box::new(self.remaining.next()).map(|f| Box::new(f) as _);
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar(Vec<Box<dyn Foo>>);
|
|
|
|
|
|
|
|
impl Bar {
|
|
|
|
fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> {
|
|
|
|
Iter {
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2020-06-09 15:57:33 -05:00
|
|
|
current: None,
|
2022-05-22 00:36:12 -05:00
|
|
|
remaining: self.0.iter(),
|
2020-06-09 15:57:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Baz(Vec<Box<dyn Foo>>);
|
|
|
|
|
|
|
|
impl Baz {
|
|
|
|
fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
|
|
|
|
Iter {
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2020-06-09 15:57:33 -05:00
|
|
|
current: None,
|
2022-05-22 00:36:12 -05:00
|
|
|
remaining: self.0.iter(),
|
2020-06-09 15:57:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bat(Vec<Box<dyn Foo>>);
|
|
|
|
|
|
|
|
impl Bat {
|
|
|
|
fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
|
|
|
|
Iter {
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2020-06-09 15:57:33 -05:00
|
|
|
current: None,
|
2022-05-22 00:36:12 -05:00
|
|
|
remaining: self.0.iter(),
|
2020-06-09 15:57:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Ban(Vec<Box<dyn Foo>>);
|
|
|
|
|
|
|
|
impl Ban {
|
|
|
|
fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> {
|
|
|
|
Iter {
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2020-06-09 15:57:33 -05:00
|
|
|
current: None,
|
2022-05-22 00:36:12 -05:00
|
|
|
remaining: self.0.iter(),
|
2020-06-09 15:57:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|