-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)GATs-triagedIssues using the `generic_associated_types` feature that have been triagedIssues using the `generic_associated_types` feature that have been triagedfixed-by-poloniusCompiling with `-Zpolonius` fixes this issue.Compiling with `-Zpolonius` fixes this issue.
Description
Currently, you can't write a safe filter
adapter for a LendingIterator
with GATs without polonius.
#![feature(generic_associated_types)]
trait LendingIterator {
type Item<'a> where Self: 'a;
fn next(&mut self) -> Option<Self::Item<'_>>;
fn filter<P>(self, predicate: P) -> Filter<Self, P>
where
Self: Sized,
P: FnMut(&Self::Item<'_>) -> bool,
{
Filter {
iter: self,
predicate,
}
}
}
pub struct Filter<I, P> {
iter: I,
predicate: P,
}
impl<I: LendingIterator, P> LendingIterator for Filter<I, P>
where
P: FnMut(&I::Item<'_>) -> bool,
{
type Item<'a> where Self: 'a = I::Item<'a>;
fn next(&mut self) -> Option<I::Item<'_>> {
while let Some(item) = self.iter.next() {
if (self.predicate)(&item) {
return Some(item);
}
}
return None;
}
}
fn main() {}
afetisov, mu001999, SeniorMars, schneiderfelipe, zohnannor and 1 morecompiler-errors, BoxyUwU, mu001999, SeniorMars, zohnannor and 3 more
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)GATs-triagedIssues using the `generic_associated_types` feature that have been triagedIssues using the `generic_associated_types` feature that have been triagedfixed-by-poloniusCompiling with `-Zpolonius` fixes this issue.Compiling with `-Zpolonius` fixes this issue.