Skip to content

Commit 5b66372

Browse files
authored
Rollup merge of rust-lang#90117 - calebsander:fix/rsplit-clone, r=yaahc
Make RSplit<T, P>: Clone not require T: Clone This addresses a TODO comment. The behavior of `#[derive(Clone)]` *does* result in a `T: Clone` requirement. Playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a8b1a9581ff8893baf401d624a53d35b Add a manual `Clone` implementation, mirroring `Split` and `SplitInclusive`. `(R)?SplitN(Mut)?` don't have any `Clone` implementations, but I'll leave that for its own pull request.
2 parents b88f86d + 29f35f4 commit 5b66372

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/slice/iter.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
839839
/// [`rsplit`]: slice::rsplit
840840
/// [slices]: slice
841841
#[stable(feature = "slice_rsplit", since = "1.27.0")]
842-
#[derive(Clone)] // Is this correct, or does it incorrectly require `T: Clone`?
843842
pub struct RSplit<'a, T: 'a, P>
844843
where
845844
P: FnMut(&T) -> bool,
@@ -867,6 +866,17 @@ where
867866
}
868867
}
869868

869+
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
870+
#[stable(feature = "slice_rsplit", since = "1.27.0")]
871+
impl<T, P> Clone for RSplit<'_, T, P>
872+
where
873+
P: Clone + FnMut(&T) -> bool,
874+
{
875+
fn clone(&self) -> Self {
876+
RSplit { inner: self.inner.clone() }
877+
}
878+
}
879+
870880
#[stable(feature = "slice_rsplit", since = "1.27.0")]
871881
impl<'a, T, P> Iterator for RSplit<'a, T, P>
872882
where

0 commit comments

Comments
 (0)