Skip to content

Commit 25b6267

Browse files
committed
Taking a peek
1 parent 4722744 commit 25b6267

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,26 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
455455

456456
// Iterate over each segment of the path.
457457
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();
460459

461460
// 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() {
463462
if let Some(&kind) = parent_substs.get(param.index as usize) {
464463
push_kind(&mut substs, kind);
465-
next_param = params.next();
464+
params.next();
466465
} else {
467466
break;
468467
}
469468
}
470469

471470
// (Unless it's been handled in `parent_substs`) `Self` is handled first.
472471
if has_self {
473-
if let Some(param) = next_param {
472+
if let Some(&param) = params.peek() {
474473
if param.index == 0 {
475474
if let GenericParamDefKind::Type { .. } = param.kind {
476475
push_kind(&mut substs, self_ty.map(|ty| ty.into())
477476
.unwrap_or_else(|| inferred_kind(None, param, true)));
478-
next_param = params.next();
477+
params.next();
479478
}
480479
}
481480
}
@@ -484,21 +483,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
484483
// Check whether this segment takes generic arguments and the user has provided any.
485484
let (generic_args, infer_types) = args_for_def_id(def_id);
486485

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();
489488

490489
loop {
491490
// We're going to iterate through the generic arguments that the user
492491
// provided, matching them with the generic parameters we expect.
493492
// Mismatches can occur as a result of elided lifetimes, or for malformed
494493
// input. We try to handle both sensibly.
495494
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)) => {
498497
match (arg, &param.kind) {
499498
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime) => {
500499
push_kind(&mut substs, provided_kind(param, arg));
501-
next_param = params.next();
500+
params.next();
502501
}
503502
(GenericArg::Lifetime(_), GenericParamDefKind::Type { .. }) => {
504503
// We expected a type argument, but got a lifetime
@@ -510,13 +509,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
510509
}
511510
(GenericArg::Type(_), GenericParamDefKind::Type { .. }) => {
512511
push_kind(&mut substs, provided_kind(param, arg));
513-
next_param = params.next();
512+
params.next();
514513
}
515514
(GenericArg::Type(_), GenericParamDefKind::Lifetime) => {
516515
// We expected a lifetime argument, but got a type
517516
// argument. That means we're inferring the lifetimes.
518517
push_kind(&mut substs, inferred_kind(None, param, infer_types));
519-
next_param = params.next();
518+
params.next();
520519
progress_arg = false;
521520
}
522521
}
@@ -526,7 +525,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
526525
// Getting to this point means the user supplied more arguments than
527526
// there are parameters.
528527
}
529-
(None, Some(param)) => {
528+
(None, Some(&param)) => {
530529
// If there are fewer arguments than parameters, it means
531530
// we're inferring the remaining arguments.
532531
match param.kind {
@@ -538,12 +537,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
538537
push_kind(&mut substs, kind);
539538
}
540539
}
541-
next_param = params.next();
540+
params.next();
542541
}
543542
(None, None) => break,
544543
}
545544
if progress_arg {
546-
next_arg = args.next();
545+
args.next();
547546
}
548547
}
549548
}

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4832,7 +4832,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48324832
Def::VariantCtor(def_id, ..) => {
48334833
// Everything but the final segment should have no
48344834
// parameters at all.
4835-
let mut generics = self.tcx.generics_of(def_id);
4835+
let generics = self.tcx.generics_of(def_id);
48364836
// Variant and struct constructors use the
48374837
// generics of their parent type definition.
48384838
let generics_def_id = generics.parent.unwrap_or(def_id);

0 commit comments

Comments
 (0)