summaryrefslogtreecommitdiffstats
path: root/src/test/ui/generic-associated-types/issue-76826.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/generic-associated-types/issue-76826.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/generic-associated-types/issue-76826.rs')
-rw-r--r--src/test/ui/generic-associated-types/issue-76826.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/ui/generic-associated-types/issue-76826.rs b/src/test/ui/generic-associated-types/issue-76826.rs
new file mode 100644
index 000000000..28eb3b0e7
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-76826.rs
@@ -0,0 +1,44 @@
+// run-pass
+
+#![feature(generic_associated_types)]
+
+pub trait Iter {
+ type Item<'a> where Self: 'a;
+
+ fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
+
+ fn for_each<F>(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<T> {
+ items: Vec<T>,
+ start: usize,
+ len: usize,
+}
+
+impl<T> Windows<T> {
+ pub fn new(items: Vec<T>, len: usize) -> Self {
+ Self { items, start: 0, len }
+ }
+}
+
+impl<T> Iter for Windows<T> {
+ type Item<'a> = &'a mut [T] where T: 'a;
+
+ fn next<'a>(&'a mut self) -> Option<Self::Item<'a>> {
+ 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));
+}