summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/manual_next_back.rs
blob: b980e90e11447766cb43c2cb1b7c0ca186746d99 (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
#![allow(unused)]
#![warn(clippy::manual_next_back)]

struct FakeIter(std::ops::Range<i32>);

impl FakeIter {
    fn rev(self) -> Self {
        self
    }

    fn next(&self) {}
}

impl DoubleEndedIterator for FakeIter {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.0.next_back()
    }
}

impl Iterator for FakeIter {
    type Item = i32;
    fn next(&mut self) -> Option<Self::Item> {
        self.0.next()
    }
}

fn main() {
    // should not lint
    FakeIter(0..10).rev().next();

    // should lint
    let _ = (0..10).rev().next().unwrap();
    let _ = "something".bytes().rev().next();
}