@@ -44,6 +44,19 @@ macro_rules! fuse {
4444 } ;
4545}
4646
47+ // NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`.
48+ // Implementing this as a directly-expanded macro helps codegen performance.
49+ macro_rules! unchecked {
50+ ( $self: ident) => {
51+ match $self {
52+ Fuse { iter: Some ( iter) } => iter,
53+ // SAFETY: the specialized iterator never sets `None`
54+ Fuse { iter: None } => unsafe { intrinsics:: unreachable( ) } ,
55+ }
56+ } ;
57+ }
58+
59+ // Any implementation here is made internal to avoid exposing default fns outside this trait
4760#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4861impl < I > Iterator for Fuse < I >
4962where
@@ -159,27 +172,6 @@ where
159172 }
160173}
161174
162- // NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`.
163- // Implementing this as a directly-expanded macro helps codegen performance.
164- macro_rules! unchecked {
165- ( $self: ident) => {
166- match $self {
167- Fuse { iter: Some ( iter) } => iter,
168- // SAFETY: the specialized iterator never sets `None`
169- Fuse { iter: None } => unsafe { intrinsics:: unreachable( ) } ,
170- }
171- } ;
172- }
173-
174- #[ stable( feature = "fused" , since = "1.26.0" ) ]
175- impl < I > Iterator for Fuse < I > where I : FusedIterator { }
176-
177- #[ stable( feature = "fused" , since = "1.26.0" ) ]
178- impl < I > DoubleEndedIterator for Fuse < I > where I : DoubleEndedIterator + FusedIterator { }
179-
180- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
181- impl < I > ExactSizeIterator for Fuse < I > where I : ExactSizeIterator + FusedIterator { }
182-
183175unsafe impl < I > TrustedRandomAccess for Fuse < I >
184176where
185177 I : TrustedRandomAccess ,
@@ -198,6 +190,9 @@ where
198190}
199191
200192// Fuse specialization trait
193+ // Iterators and DoubleEndedIterators cannot be overlapped successfully
194+ // So, they're separated into each it's own trait to provide internal implementations
195+ // Similarly, ExactSizeIterators cannot be overlapped, so requires its own trait
201196#[ doc( hidden) ]
202197trait FuseIteratorImpl < I > {
203198 type Item ;
0 commit comments