From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/generic-associated-types/issue-76826.rs | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/ui/generic-associated-types/issue-76826.rs (limited to 'tests/ui/generic-associated-types/issue-76826.rs') diff --git a/tests/ui/generic-associated-types/issue-76826.rs b/tests/ui/generic-associated-types/issue-76826.rs new file mode 100644 index 000000000..ead78453e --- /dev/null +++ b/tests/ui/generic-associated-types/issue-76826.rs @@ -0,0 +1,42 @@ +// run-pass + +pub trait Iter { + type Item<'a> where Self: 'a; + + fn next<'a>(&'a mut self) -> Option>; + + fn for_each(mut self, mut f: F) + where Self: Sized, F: for<'a> FnMut(Self::Item<'a>) + { + while let Some(item) = self.next() { + f(item); + } + } +} + +pub struct Windows { + items: Vec, + start: usize, + len: usize, +} + +impl Windows { + pub fn new(items: Vec, len: usize) -> Self { + Self { items, start: 0, len } + } +} + +impl Iter for Windows { + type Item<'a> = &'a mut [T] where T: 'a; + + fn next<'a>(&'a mut self) -> Option> { + let slice = self.items.get_mut(self.start..self.start + self.len)?; + self.start += 1; + Some(slice) + } +} + +fn main() { + Windows::new(vec![1, 2, 3, 4, 5], 3) + .for_each(|slice| println!("{:?}", slice)); +} -- cgit v1.2.3