1 #![warn(clippy::unused_peekable)]
2 #![allow(clippy::no_effect)]
5 use std
::iter
::Peekable
;
12 #[allow(clippy::unused_unit)]
14 let peekable
= std
::iter
::empty
::<u32>().peekable();
16 // Only lint `new_local`
17 let old_local
= std
::iter
::empty
::<u32>().peekable();
18 let new_local
= old_local
;
21 let mut by_mut_ref_test
= std
::iter
::empty
::<u32>().peekable();
22 let by_mut_ref
= &mut by_mut_ref_test
;
24 // Explicitly returns `Peekable`
25 fn returns_peekable() -> Peekable
<Empty
<u32>> {
26 std
::iter
::empty().peekable()
29 let peekable_from_fn
= returns_peekable();
31 // Using a method not exclusive to `Peekable`
32 let mut peekable_using_iterator_method
= std
::iter
::empty
::<u32>().peekable();
33 peekable_using_iterator_method
.next();
35 // Passed by ref to another function
36 fn takes_ref(_peek
: &Peekable
<Empty
<u32>>) {}
37 let passed_along_ref
= std
::iter
::empty
::<u32>().peekable();
38 takes_ref(&passed_along_ref
);
40 // `by_ref` without `peek`
41 let mut by_ref_test
= std
::iter
::empty
::<u32>().peekable();
42 let _by_ref
= by_ref_test
.by_ref();
44 let mut peekable_in_for_loop
= std
::iter
::empty
::<u32>().peekable();
45 for x
in peekable_in_for_loop {}
49 fn takes_peekable(_peek
: Peekable
<Empty
<u32>>) {}
51 // Passed to another function
52 let passed_along
= std
::iter
::empty
::<u32>().peekable();
53 takes_peekable(passed_along
);
55 // Passed to another method
56 struct PeekableConsumer
;
57 impl PeekableConsumer
{
58 fn consume(&self, _
: Peekable
<Empty
<u32>>) {}
59 fn consume_mut_ref(&self, _
: &mut Peekable
<Empty
<u32>>) {}
62 let peekable_consumer
= PeekableConsumer
;
63 let mut passed_along_to_method
= std
::iter
::empty
::<u32>().peekable();
64 peekable_consumer
.consume_mut_ref(&mut passed_along_to_method
);
65 peekable_consumer
.consume(passed_along_to_method
);
67 // `peek` called in another block
68 let mut peekable_in_block
= std
::iter
::empty
::<u32>().peekable();
70 peekable_in_block
.peek();
73 // Check the other `Peekable` methods :)
75 let mut peekable_with_peek_mut
= std
::iter
::empty
::<u32>().peekable();
76 peekable_with_peek_mut
.peek_mut();
78 let mut peekable_with_next_if
= std
::iter
::empty
::<u32>().peekable();
79 peekable_with_next_if
.next_if(|_
| true);
81 let mut peekable_with_next_if_eq
= std
::iter
::empty
::<u32>().peekable();
82 peekable_with_next_if_eq
.next_if_eq(&3);
85 let mut peekable_in_closure
= std
::iter
::empty
::<u32>().peekable();
86 let call_peek
= |p
: &mut Peekable
<Empty
<u32>>| {
89 call_peek(&mut peekable_in_closure
);
92 macro_rules
! make_me_a_peekable_please
{
94 std
::iter
::empty
::<u32>().peekable()
98 let _unsuspecting_macro_user
= make_me_a_peekable_please
!();
100 // Generic Iterator returned
101 fn return_an_iter() -> impl Iterator
<Item
= u32> {
102 std
::iter
::empty
::<u32>().peekable()
105 let _unsuspecting_user
= return_an_iter();
107 // Call `peek` in a macro
108 macro_rules
! peek_iter
{
114 let mut peek_in_macro
= std
::iter
::empty
::<u32>().peekable();
115 peek_iter
!(peek_in_macro
);
118 let mut by_mut_ref_test
= std
::iter
::empty
::<u32>().peekable();
119 let by_mut_ref
= &mut by_mut_ref_test
;
123 let mut by_ref_test
= std
::iter
::empty
::<u32>().peekable();
124 let by_ref
= &by_ref_test
;
128 struct PeekableWrapper
{
129 f
: Peekable
<Empty
<u32>>,
132 let struct_test
= std
::iter
::empty
::<u32>().peekable();
133 PeekableWrapper { f: struct_test }
;
135 // `by_ref` before `peek`
136 let mut by_ref_test
= std
::iter
::empty
::<u32>().peekable();
137 let peeked_val
= by_ref_test
.by_ref().peek();
139 // `peek` called in another block as the last expression
140 let mut peekable_last_expr
= std
::iter
::empty
::<u32>().peekable();
142 peekable_last_expr
.peek();