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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
//@no-rustfix
//@aux-build:proc_macros.rs
#![warn(clippy::iter_without_into_iter)]
#![allow(clippy::needless_lifetimes)]
extern crate proc_macros;
pub struct S1;
impl S1 {
pub fn iter(&self) -> std::slice::Iter<'_, u8> {
//~^ iter_without_into_iter
[].iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> {
//~^ iter_without_into_iter
[].iter_mut()
}
}
pub struct S2;
impl S2 {
pub fn iter(&self) -> impl Iterator<Item = &u8> {
// RPITIT is not stable, so we can't generally suggest it here yet
[].iter()
}
}
pub struct S3<'a>(&'a mut [u8]);
impl<'a> S3<'a> {
pub fn iter(&self) -> std::slice::Iter<'_, u8> {
//~^ iter_without_into_iter
self.0.iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> {
//~^ iter_without_into_iter
self.0.iter_mut()
}
}
// Incompatible signatures
pub struct S4;
impl S4 {
pub fn iter(self) -> std::slice::Iter<'static, u8> {
todo!()
}
}
pub struct S5;
impl S5 {
pub async fn iter(&self) -> std::slice::Iter<'static, u8> {
todo!()
}
}
pub struct S6;
impl S6 {
pub fn iter(&self, _additional_param: ()) -> std::slice::Iter<'static, u8> {
todo!()
}
}
pub struct S7<T>(T);
impl<T> S7<T> {
pub fn iter<U>(&self) -> std::slice::Iter<'static, (T, U)> {
todo!()
}
}
pub struct S8<T>(T);
impl<T> S8<T> {
pub fn iter(&self) -> std::slice::Iter<'static, T> {
//~^ iter_without_into_iter
todo!()
}
}
// ===========================
pub struct S9<T>(T);
impl<T> S9<T> {
pub fn iter(&self) -> std::slice::Iter<'_, T> {
//~^ iter_without_into_iter
todo!()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> {
//~^ iter_without_into_iter
todo!()
}
}
pub struct S10<T>(T);
impl<T> S10<T> {
pub fn iter(&self) -> std::slice::Iter<'_, T> {
// Don't lint, there's an existing (wrong) IntoIterator impl
todo!()
}
}
impl<'a, T> IntoIterator for &'a S10<T> {
type Item = &'a String;
type IntoIter = std::slice::Iter<'a, String>;
fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
pub struct S11<T>(T);
impl<T> S11<T> {
pub fn iter_mut(&self) -> std::slice::IterMut<'_, T> {
// Don't lint, there's an existing (wrong) IntoIterator impl
todo!()
}
}
impl<'a, T> IntoIterator for &'a mut S11<T> {
type Item = &'a mut String;
type IntoIter = std::slice::IterMut<'a, String>;
fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
// Private type not exported: don't lint
struct S12;
impl S12 {
fn iter(&self) -> std::slice::Iter<'_, u8> {
todo!()
}
}
pub struct Issue12037;
macro_rules! generate_impl {
() => {
impl Issue12037 {
fn iter(&self) -> std::slice::Iter<'_, u8> {
//~^ iter_without_into_iter
todo!()
}
}
};
}
generate_impl!();
proc_macros::external! {
pub struct ImplWithForeignSpan;
impl ImplWithForeignSpan {
fn iter(&self) -> std::slice::Iter<'_, u8> {
todo!()
}
}
}
pub struct Allowed;
impl Allowed {
#[allow(clippy::iter_without_into_iter)]
pub fn iter(&self) -> std::slice::Iter<'_, u8> {
todo!()
}
}
fn main() {}
|