]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/copy_iterator.rs
Add 'src/tools/clippy/' from commit 'd2708873ef711ec8ab45df1e984ecf24a96cd369'
[rust.git] / src / tools / clippy / tests / ui / copy_iterator.rs
1 #![warn(clippy::copy_iterator)]
2
3 #[derive(Copy, Clone)]
4 struct Countdown(u8);
5
6 impl Iterator for Countdown {
7     type Item = u8;
8
9     fn next(&mut self) -> Option<u8> {
10         self.0.checked_sub(1).map(|c| {
11             self.0 = c;
12             c
13         })
14     }
15 }
16
17 fn main() {
18     let my_iterator = Countdown(5);
19     let a: Vec<_> = my_iterator.take(1).collect();
20     assert_eq!(a.len(), 1);
21     let b: Vec<_> = my_iterator.collect();
22     assert_eq!(b.len(), 5);
23 }