@@ -18,6 +18,11 @@ use core::ops::Deref;
1818use core:: ptr:: { self , NonNull } ;
1919use core:: slice:: { self } ;
2020
21+ #[ cfg( version( "1.70" ) ) ]
22+ type AdvanceRet = core:: num:: NonZeroUsize ;
23+ #[ cfg( not( version( "1.70" ) ) ) ]
24+ type AdvanceRet = usize ;
25+
2126/// An iterator that moves out of a vector.
2227///
2328/// This `struct` is created by the `into_iter` method on [`Vec`](super::Vec)
@@ -215,7 +220,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
215220 }
216221
217222 #[ inline]
218- fn advance_by ( & mut self , n : usize ) -> Result < ( ) , usize > {
223+ fn advance_by ( & mut self , n : usize ) -> Result < ( ) , AdvanceRet > {
219224 let step_size = self . len ( ) . min ( n) ;
220225 let to_drop = ptr:: slice_from_raw_parts_mut ( self . ptr as * mut T , step_size) ;
221226 if T :: IS_ZST {
@@ -230,6 +235,9 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
230235 ptr:: drop_in_place ( to_drop) ;
231236 }
232237 if step_size < n {
238+ #[ cfg( version( "1.70" ) ) ]
239+ return Err ( AdvanceRet :: new ( step_size) . unwrap ( ) ) ;
240+ #[ cfg( not( version( "1.70" ) ) ) ]
233241 return Err ( step_size) ;
234242 }
235243 Ok ( ( ) )
@@ -315,7 +323,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
315323 }
316324
317325 #[ inline]
318- fn advance_back_by ( & mut self , n : usize ) -> Result < ( ) , usize > {
326+ fn advance_back_by ( & mut self , n : usize ) -> Result < ( ) , AdvanceRet > {
319327 let step_size = self . len ( ) . min ( n) ;
320328 if T :: IS_ZST {
321329 // SAFETY: same as for advance_by()
@@ -330,6 +338,9 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
330338 ptr:: drop_in_place ( to_drop) ;
331339 }
332340 if step_size < n {
341+ #[ cfg( version( "1.70" ) ) ]
342+ return Err ( AdvanceRet :: new ( step_size) . unwrap ( ) ) ;
343+ #[ cfg( not( version( "1.70" ) ) ) ]
333344 return Err ( step_size) ;
334345 }
335346 Ok ( ( ) )
0 commit comments