@@ -455,27 +455,26 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
455
455
456
456
// Iterate over each segment of the path.
457
457
while let Some ( ( def_id, defs) ) = stack. pop ( ) {
458
- let mut params = defs. params . iter ( ) ;
459
- let mut next_param = params. next ( ) ;
458
+ let mut params = defs. params . iter ( ) . peekable ( ) ;
460
459
461
460
// If we have already computed substitutions for parents, we can use those directly.
462
- while let Some ( param) = next_param {
461
+ while let Some ( & param) = params . peek ( ) {
463
462
if let Some ( & kind) = parent_substs. get ( param. index as usize ) {
464
463
push_kind ( & mut substs, kind) ;
465
- next_param = params. next ( ) ;
464
+ params. next ( ) ;
466
465
} else {
467
466
break ;
468
467
}
469
468
}
470
469
471
470
// (Unless it's been handled in `parent_substs`) `Self` is handled first.
472
471
if has_self {
473
- if let Some ( param) = next_param {
472
+ if let Some ( & param) = params . peek ( ) {
474
473
if param. index == 0 {
475
474
if let GenericParamDefKind :: Type { .. } = param. kind {
476
475
push_kind ( & mut substs, self_ty. map ( |ty| ty. into ( ) )
477
476
. unwrap_or_else ( || inferred_kind ( None , param, true ) ) ) ;
478
- next_param = params. next ( ) ;
477
+ params. next ( ) ;
479
478
}
480
479
}
481
480
}
@@ -484,21 +483,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
484
483
// Check whether this segment takes generic arguments and the user has provided any.
485
484
let ( generic_args, infer_types) = args_for_def_id ( def_id) ;
486
485
487
- let mut args = generic_args. iter ( ) . flat_map ( |generic_args| generic_args. args . iter ( ) ) ;
488
- let mut next_arg = args . next ( ) ;
486
+ let mut args = generic_args. iter ( ) . flat_map ( |generic_args| generic_args. args . iter ( ) )
487
+ . peekable ( ) ;
489
488
490
489
loop {
491
490
// We're going to iterate through the generic arguments that the user
492
491
// provided, matching them with the generic parameters we expect.
493
492
// Mismatches can occur as a result of elided lifetimes, or for malformed
494
493
// input. We try to handle both sensibly.
495
494
let mut progress_arg = true ;
496
- match ( next_arg , next_param ) {
497
- ( Some ( arg) , Some ( param) ) => {
495
+ match ( args . peek ( ) , params . peek ( ) ) {
496
+ ( Some ( & arg) , Some ( & param) ) => {
498
497
match ( arg, & param. kind ) {
499
498
( GenericArg :: Lifetime ( _) , GenericParamDefKind :: Lifetime ) => {
500
499
push_kind ( & mut substs, provided_kind ( param, arg) ) ;
501
- next_param = params. next ( ) ;
500
+ params. next ( ) ;
502
501
}
503
502
( GenericArg :: Lifetime ( _) , GenericParamDefKind :: Type { .. } ) => {
504
503
// We expected a type argument, but got a lifetime
@@ -510,13 +509,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
510
509
}
511
510
( GenericArg :: Type ( _) , GenericParamDefKind :: Type { .. } ) => {
512
511
push_kind ( & mut substs, provided_kind ( param, arg) ) ;
513
- next_param = params. next ( ) ;
512
+ params. next ( ) ;
514
513
}
515
514
( GenericArg :: Type ( _) , GenericParamDefKind :: Lifetime ) => {
516
515
// We expected a lifetime argument, but got a type
517
516
// argument. That means we're inferring the lifetimes.
518
517
push_kind ( & mut substs, inferred_kind ( None , param, infer_types) ) ;
519
- next_param = params. next ( ) ;
518
+ params. next ( ) ;
520
519
progress_arg = false ;
521
520
}
522
521
}
@@ -526,7 +525,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
526
525
// Getting to this point means the user supplied more arguments than
527
526
// there are parameters.
528
527
}
529
- ( None , Some ( param) ) => {
528
+ ( None , Some ( & param) ) => {
530
529
// If there are fewer arguments than parameters, it means
531
530
// we're inferring the remaining arguments.
532
531
match param. kind {
@@ -538,12 +537,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
538
537
push_kind ( & mut substs, kind) ;
539
538
}
540
539
}
541
- next_param = params. next ( ) ;
540
+ params. next ( ) ;
542
541
}
543
542
( None , None ) => break ,
544
543
}
545
544
if progress_arg {
546
- next_arg = args. next ( ) ;
545
+ args. next ( ) ;
547
546
}
548
547
}
549
548
}
0 commit comments