Skip to content

Commit 270c800

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 c400fee + afcee19 commit 270c800

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

library/core/src/slice/iter.rs

+11-1
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

src/test/ui/iterators/rsplit-clone.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
3+
// RSplit<T, P> previously required T: Clone in order to be Clone
4+
5+
struct NotClone;
6+
7+
fn main() {
8+
let elements = [NotClone, NotClone, NotClone];
9+
let rsplit = elements.rsplit(|_| false);
10+
rsplit.clone();
11+
}

0 commit comments

Comments
 (0)