a-mir-formality icon indicating copy to clipboard operation
a-mir-formality copied to clipboard

lending-iterator spike

Open nikomatsakis opened this issue 3 years ago • 0 comments

Model the lending iterator example:

https://github.com/rust-lang/rust/blob/master/src/test/ui/generic-associated-types/extended/lending_iterator_2.rs

#![feature(generic_associated_types)]

pub trait LendingIterator {
    type Item<'a>
    where
        Self: 'a;
    fn next(&mut self) -> Option<Self::Item<'_>>;
}

pub trait FromLendingIterator<A>: Sized {
    fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
}

impl<A> FromLendingIterator<A> for Vec<A> {
    fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
        let mut v = vec![];
        while let Some(item) = iter.next() {
            v.push(item);
        }
        v
    }
}

fn main() {}
  • [x] #41
  • [x] Extend trait items with associated functions
  • [x] #64
  • [x] #69
  • [x] Add lowering of associated type definitions
  • [x] Add implied bounds for higher-ranked where-clauses
  • [ ] https://github.com/nikomatsakis/a-mir-formality/issues/28
  • [ ] https://github.com/nikomatsakis/a-mir-formality/issues/30
  • [ ] https://github.com/nikomatsakis/a-mir-formality/issues/29

nikomatsakis avatar May 27 '22 09:05 nikomatsakis