]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs
skip if val has ecaping bound vars
[rust.git] / src / test / ui / suggestions / lifetimes / trait-object-nested-in-impl-trait.rs
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 {
29             //~^ ERROR lifetime may not live long enough
30             current: None,
31             remaining: self.0.iter(),
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 {
41             //~^ ERROR lifetime may not live long enough
42             current: None,
43             remaining: self.0.iter(),
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 {
53             //~^ ERROR lifetime may not live long enough
54             current: None,
55             remaining: self.0.iter(),
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 {
65             //~^ ERROR lifetime may not live long enough
66             current: None,
67             remaining: self.0.iter(),
68         }
69     }
70 }
71
72 fn main() {}