summaryrefslogtreecommitdiffstats
path: root/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs
blob: ff27011f89e8391b07e18a19488409cec44b347b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 {
            //~^ ERROR lifetime may not live long enough
            current: None,
            remaining: self.0.iter(),
        }
    }
}

struct Baz(Vec<Box<dyn Foo>>);

impl Baz {
    fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
        Iter {
            //~^ ERROR lifetime may not live long enough
            current: None,
            remaining: self.0.iter(),
        }
    }
}

struct Bat(Vec<Box<dyn Foo>>);

impl Bat {
    fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
        Iter {
            //~^ ERROR lifetime may not live long enough
            current: None,
            remaining: self.0.iter(),
        }
    }
}

struct Ban(Vec<Box<dyn Foo>>);

impl Ban {
    fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> {
        Iter {
            //~^ ERROR lifetime may not live long enough
            current: None,
            remaining: self.0.iter(),
        }
    }
}

fn main() {}