@@ -44,6 +44,19 @@ macro_rules! fuse {
44
44
} ;
45
45
}
46
46
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
47
60
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
48
61
impl < I > Iterator for Fuse < I >
49
62
where
@@ -159,27 +172,6 @@ where
159
172
}
160
173
}
161
174
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
-
183
175
unsafe impl < I > TrustedRandomAccess for Fuse < I >
184
176
where
185
177
I : TrustedRandomAccess ,
@@ -198,6 +190,9 @@ where
198
190
}
199
191
200
192
// 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
201
196
#[ doc( hidden) ]
202
197
trait FuseIteratorImpl < I > {
203
198
type Item ;
0 commit comments