]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | trait Foo {} |
2 | impl<'a, T: Foo> Foo for &'a T {} | |
3 | impl<T: Foo + ?Sized> Foo for Box<T> {} | |
4 | ||
5 | struct Iter<'a, T> { | |
6 | current: Option<Box<dyn Foo + 'a>>, | |
7 | remaining: T, | |
8 | } | |
9 | ||
10 | impl<'a, T> Iterator for Iter<'a, T> | |
11 | where | |
12 | T: Iterator, | |
13 | T::Item: Foo + 'a, | |
14 | { | |
15 | type Item = Box<dyn Foo + 'a>; | |
16 | ||
17 | fn next(&mut self) -> Option<Self::Item> { | |
18 | let result = self.current.take(); | |
19 | self.current = Box::new(self.remaining.next()).map(|f| Box::new(f) as _); | |
20 | result | |
21 | } | |
22 | } | |
23 | ||
24 | struct Bar(Vec<Box<dyn Foo>>); | |
25 | ||
26 | impl Bar { | |
27 | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> { | |
28 | Iter { | |
923072b8 | 29 | //~^ ERROR lifetime may not live long enough |
f035d41b | 30 | current: None, |
923072b8 | 31 | remaining: self.0.iter(), |
f035d41b XL |
32 | } |
33 | } | |
34 | } | |
35 | ||
36 | struct Baz(Vec<Box<dyn Foo>>); | |
37 | ||
38 | impl Baz { | |
39 | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ { | |
40 | Iter { | |
923072b8 | 41 | //~^ ERROR lifetime may not live long enough |
f035d41b | 42 | current: None, |
923072b8 | 43 | remaining: self.0.iter(), |
f035d41b XL |
44 | } |
45 | } | |
46 | } | |
47 | ||
48 | struct Bat(Vec<Box<dyn Foo>>); | |
49 | ||
50 | impl Bat { | |
51 | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a { | |
52 | Iter { | |
923072b8 | 53 | //~^ ERROR lifetime may not live long enough |
f035d41b | 54 | current: None, |
923072b8 | 55 | remaining: self.0.iter(), |
f035d41b XL |
56 | } |
57 | } | |
58 | } | |
59 | ||
60 | struct Ban(Vec<Box<dyn Foo>>); | |
61 | ||
62 | impl Ban { | |
63 | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> { | |
64 | Iter { | |
923072b8 | 65 | //~^ ERROR lifetime may not live long enough |
f035d41b | 66 | current: None, |
923072b8 | 67 | remaining: self.0.iter(), |
f035d41b XL |
68 | } |
69 | } | |
70 | } | |
71 | ||
72 | fn main() {} |