Skip to content

Commit ba05b76

Browse files
committed
Add regression test for rust-lang#12964
1 parent 567bea2 commit ba05b76

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/ui/into_iter_without_iter.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,42 @@ pub mod issue11635 {
185185
}
186186
}
187187
}
188+
189+
pub mod issue12964 {
190+
pub struct MyIter<'a, T: 'a> {
191+
iter: std::slice::Iter<'a, T>,
192+
}
193+
194+
impl<'a, T> Iterator for MyIter<'a, T> {
195+
type Item = &'a T;
196+
197+
fn next(&mut self) -> Option<Self::Item> {
198+
self.iter.next()
199+
}
200+
}
201+
202+
pub struct MyContainer<T> {
203+
inner: Vec<T>,
204+
}
205+
206+
impl<T> MyContainer<T> {}
207+
208+
impl<T> MyContainer<T> {
209+
#[must_use]
210+
pub fn iter(&self) -> MyIter<'_, T> {
211+
<&Self as IntoIterator>::into_iter(self)
212+
}
213+
}
214+
215+
impl<'a, T> IntoIterator for &'a MyContainer<T> {
216+
type Item = &'a T;
217+
218+
type IntoIter = MyIter<'a, T>;
219+
220+
fn into_iter(self) -> Self::IntoIter {
221+
Self::IntoIter {
222+
iter: self.inner.as_slice().iter(),
223+
}
224+
}
225+
}
226+
}

0 commit comments

Comments
 (0)