summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs
blob: cce216fc649b1667d276f9283ea4c273d146c5cb (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
73
74
#![warn(clippy::iter_not_returning_iterator)]

struct Data {
    begin: u32,
}

struct Counter {
    count: u32,
}

impl Data {
    fn iter(&self) -> Counter {
        todo!()
    }

    fn iter_mut(&self) -> Counter {
        todo!()
    }
}

struct Data2 {
    begin: u32,
}

struct Counter2 {
    count: u32,
}

impl Data2 {
    fn iter(&self) -> Counter2 {
        todo!()
    }

    fn iter_mut(&self) -> Counter2 {
        todo!()
    }
}

impl Iterator for Counter {
    type Item = u32;

    fn next(&mut self) -> Option<Self::Item> {
        todo!()
    }
}

// Issue #8225
trait Iter {
    type I;
    fn iter(&self) -> Self::I;
}

impl Iter for () {
    type I = core::slice::Iter<'static, ()>;
    fn iter(&self) -> Self::I {
        [].iter()
    }
}

struct S;
impl S {
    fn iter(&self) -> <() as Iter>::I {
        ().iter()
    }
}

struct S2([u8]);
impl S2 {
    fn iter(&self) -> core::slice::Iter<u8> {
        self.0.iter()
    }
}

fn main() {}