@@ -395,24 +395,36 @@ fn test_windows_zip() {
395
395
fn test_iter_ref_consistency ( ) {
396
396
use std:: fmt:: Debug ;
397
397
398
- fn helper < T : Copy + Debug + PartialEq > ( x : T ) {
398
+ fn test < T : Copy + Debug + PartialEq > ( x : T ) {
399
399
let v : & [ T ] = & [ x, x, x] ;
400
400
let v_ptrs : [ * const T ; 3 ] = match v {
401
401
[ ref v1, ref v2, ref v3] => [ v1 as * const _ , v2 as * const _ , v3 as * const _ ] ,
402
402
_ => unreachable ! ( )
403
403
} ;
404
404
let len = v. len ( ) ;
405
405
406
+ // nth(i)
406
407
for i in 0 ..len {
407
408
assert_eq ! ( & v[ i] as * const _, v_ptrs[ i] ) ; // check the v_ptrs array, just to be sure
408
409
let nth = v. iter ( ) . nth ( i) . unwrap ( ) ;
409
410
assert_eq ! ( nth as * const _, v_ptrs[ i] ) ;
410
411
}
411
412
assert_eq ! ( v. iter( ) . nth( len) , None , "nth(len) should return None" ) ;
412
413
414
+ // stepping through with nth(0)
413
415
{
414
416
let mut it = v. iter ( ) ;
415
- for i in 0 ..len{
417
+ for i in 0 ..len {
418
+ let next = it. nth ( 0 ) . unwrap ( ) ;
419
+ assert_eq ! ( next as * const _, v_ptrs[ i] ) ;
420
+ }
421
+ assert_eq ! ( it. nth( 0 ) , None ) ;
422
+ }
423
+
424
+ // next()
425
+ {
426
+ let mut it = v. iter ( ) ;
427
+ for i in 0 ..len {
416
428
let remaining = len - i;
417
429
assert_eq ! ( it. size_hint( ) , ( remaining, Some ( remaining) ) ) ;
418
430
@@ -423,9 +435,10 @@ fn test_iter_ref_consistency() {
423
435
assert_eq ! ( it. next( ) , None , "The final call to next() should return None" ) ;
424
436
}
425
437
438
+ // next_back()
426
439
{
427
440
let mut it = v. iter ( ) ;
428
- for i in 0 ..len{
441
+ for i in 0 ..len {
429
442
let remaining = len - i;
430
443
assert_eq ! ( it. size_hint( ) , ( remaining, Some ( remaining) ) ) ;
431
444
@@ -437,7 +450,7 @@ fn test_iter_ref_consistency() {
437
450
}
438
451
}
439
452
440
- fn helper_mut < T : Copy + Debug + PartialEq > ( x : T ) {
453
+ fn test_mut < T : Copy + Debug + PartialEq > ( x : T ) {
441
454
let v : & mut [ T ] = & mut [ x, x, x] ;
442
455
let v_ptrs : [ * mut T ; 3 ] = match v {
443
456
[ ref v1, ref v2, ref v3] =>
@@ -446,13 +459,25 @@ fn test_iter_ref_consistency() {
446
459
} ;
447
460
let len = v. len ( ) ;
448
461
462
+ // nth(i)
449
463
for i in 0 ..len {
450
464
assert_eq ! ( & mut v[ i] as * mut _, v_ptrs[ i] ) ; // check the v_ptrs array, just to be sure
451
465
let nth = v. iter_mut ( ) . nth ( i) . unwrap ( ) ;
452
466
assert_eq ! ( nth as * mut _, v_ptrs[ i] ) ;
453
467
}
454
468
assert_eq ! ( v. iter( ) . nth( len) , None , "nth(len) should return None" ) ;
455
469
470
+ // stepping through with nth(0)
471
+ {
472
+ let mut it = v. iter ( ) ;
473
+ for i in 0 ..len {
474
+ let next = it. nth ( 0 ) . unwrap ( ) ;
475
+ assert_eq ! ( next as * const _, v_ptrs[ i] ) ;
476
+ }
477
+ assert_eq ! ( it. nth( 0 ) , None ) ;
478
+ }
479
+
480
+ // next()
456
481
{
457
482
let mut it = v. iter_mut ( ) ;
458
483
for i in 0 ..len {
@@ -466,9 +491,10 @@ fn test_iter_ref_consistency() {
466
491
assert_eq ! ( it. next( ) , None , "The final call to next() should return None" ) ;
467
492
}
468
493
494
+ // next_back()
469
495
{
470
496
let mut it = v. iter_mut ( ) ;
471
- for i in 0 ..len{
497
+ for i in 0 ..len {
472
498
let remaining = len - i;
473
499
assert_eq ! ( it. size_hint( ) , ( remaining, Some ( remaining) ) ) ;
474
500
@@ -482,12 +508,12 @@ fn test_iter_ref_consistency() {
482
508
483
509
// Make sure iterators and slice patterns yield consistent addresses for various types,
484
510
// including ZSTs.
485
- helper ( 0u32 ) ;
486
- helper ( ( ) ) ;
487
- helper ( [ 0u32 ; 0 ] ) ; // ZST with alignment > 0
488
- helper_mut ( 0u32 ) ;
489
- helper_mut ( ( ) ) ;
490
- helper_mut ( [ 0u32 ; 0 ] ) ; // ZST with alignment > 0
511
+ test ( 0u32 ) ;
512
+ test ( ( ) ) ;
513
+ test ( [ 0u32 ; 0 ] ) ; // ZST with alignment > 0
514
+ test_mut ( 0u32 ) ;
515
+ test_mut ( ( ) ) ;
516
+ test_mut ( [ 0u32 ; 0 ] ) ; // ZST with alignment > 0
491
517
}
492
518
493
519
// The current implementation of SliceIndex fails to handle methods
0 commit comments