From e6229e6d770e87c173ddfb75c97ed11bbb64e936 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 23 Nov 2022 19:50:02 +0900 Subject: [PATCH] revset: turn RevWalkRevset into generic wrapper of cloneable iterator I failed to solve type puzzle for to_predicate_fn<'a>(&'a self) where 'repo: 'a, so struct RevWalkRevset<'repo, T> is bounded by T to consume the lifetime parameter. --- lib/src/revset.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 98166c6b8..c6f47f6fb 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -32,7 +32,7 @@ use thiserror::Error; use crate::backend::{BackendError, BackendResult, CommitId}; use crate::commit::Commit; -use crate::index::{HexPrefix, IndexEntry, PrefixResolution, RevWalk}; +use crate::index::{HexPrefix, IndexEntry, PrefixResolution}; use crate::matchers::{EverythingMatcher, Matcher, PrefixMatcher}; use crate::op_store::WorkspaceId; use crate::repo::RepoRef; @@ -1434,17 +1434,28 @@ impl<'repo> ToPredicateFn<'repo> for EagerRevset<'repo> { } } -struct RevWalkRevset<'repo> { - walk: RevWalk<'repo>, +struct RevWalkRevset<'repo, T> +where + // RevWalkRevset<'repo> appears to be needed to assert 'repo outlives 'a + // in to_predicate_fn<'a>(&'a self) -> Box. + T: Iterator>, +{ + walk: T, } -impl<'repo> Revset<'repo> for RevWalkRevset<'repo> { +impl<'repo, T> Revset<'repo> for RevWalkRevset<'repo, T> +where + T: Iterator> + Clone, +{ fn iter<'revset>(&'revset self) -> RevsetIterator<'revset, 'repo> { RevsetIterator::new(Box::new(self.walk.clone())) } } -impl<'repo> ToPredicateFn<'repo> for RevWalkRevset<'repo> { +impl<'repo, T> ToPredicateFn<'repo> for RevWalkRevset<'repo, T> +where + T: Iterator> + Clone, +{ fn to_predicate_fn(&self) -> Box) -> bool + '_> { self.iter().into_predicate_fn() }