Skip to content

Commit 9d3d4b1

Browse files
committed
Refactor lock-step
1 parent 6a96cf1 commit 9d3d4b1

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -267,29 +267,33 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
267267

268268
// Check whether this segment takes generic arguments and the user has provided any.
269269
let (generic_args, infer_types) = args_for_def_id(def_id);
270-
if let Some(ref generic_args) = generic_args {
270+
271+
let mut args = generic_args.iter().flat_map(|generic_args| generic_args.args.iter());
272+
let mut next_arg = args.next();
273+
274+
loop {
271275
// We're going to iterate through the generic arguments that the user
272276
// provided, matching them with the generic parameters we expect.
273277
// Mismatches can occur as a result of elided lifetimes, or for malformed
274278
// input. We try to handle both sensibly.
275-
'args: for arg in &generic_args.args {
276-
while let Some(param) = next_param {
279+
let mut progress_arg = true;
280+
match (next_arg, next_param) {
281+
(Some(arg), Some(param)) => {
277282
match (&param.kind, arg) {
278283
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(_)) => {
279284
push_kind(&mut substs, provided_kind(param, arg));
280285
next_param = params.next();
281-
continue 'args;
282286
}
283287
(GenericParamDefKind::Lifetime, GenericArg::Type(_)) => {
284288
// We expected a lifetime argument, but got a type
285289
// argument. That means we're inferring the lifetimes.
286290
push_kind(&mut substs, inferred_kind(None, param, infer_types));
287291
next_param = params.next();
292+
progress_arg = false;
288293
}
289294
(GenericParamDefKind::Type { .. }, GenericArg::Type(_)) => {
290295
push_kind(&mut substs, provided_kind(param, arg));
291296
next_param = params.next();
292-
continue 'args;
293297
}
294298
(GenericParamDefKind::Type { .. }, GenericArg::Lifetime(_)) => {
295299
// We expected a type argument, but got a lifetime
@@ -300,35 +304,43 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
300304
if err_if_invalid {
301305
tcx.sess.delay_span_bug(span,
302306
"found a GenericArg::Lifetime where a \
303-
GenericArg::Type was expected");
307+
GenericArg::Type was expected");
308+
}
309+
// Exhaust the iterator.
310+
while next_arg.is_some() {
311+
next_arg = args.next();
304312
}
305-
break 'args;
306313
}
307314
}
308315
}
309-
// We should never be able to reach this point with well-formed input.
310-
// Getting to this point means the user supplied more arguments than
311-
// there are parameters.
312-
if err_if_invalid {
313-
tcx.sess.delay_span_bug(span,
314-
"GenericArg did not have matching GenericParamDef");
315-
}
316-
}
317-
}
318-
319-
// If there are fewer arguments than parameters, it means
320-
// we're inferring the remaining arguments.
321-
while let Some(param) = next_param {
322-
match param.kind {
323-
GenericParamDefKind::Lifetime => {
324-
push_kind(&mut substs, inferred_kind(None, param, infer_types));
316+
(Some(_), None) => {
317+
// We should never be able to reach this point with well-formed input.
318+
// Getting to this point means the user supplied more arguments than
319+
// there are parameters.
320+
if err_if_invalid {
321+
tcx.sess.delay_span_bug(span,
322+
"GenericArg did not have matching GenericParamDef");
323+
}
325324
}
326-
GenericParamDefKind::Type { .. } => {
327-
let kind = inferred_kind(Some(&substs), param, infer_types);
328-
push_kind(&mut substs, kind);
325+
(None, Some(param)) => {
326+
// If there are fewer arguments than parameters, it means
327+
// we're inferring the remaining arguments.
328+
match param.kind {
329+
GenericParamDefKind::Lifetime => {
330+
push_kind(&mut substs, inferred_kind(None, param, infer_types));
331+
}
332+
GenericParamDefKind::Type { .. } => {
333+
let kind = inferred_kind(Some(&substs), param, infer_types);
334+
push_kind(&mut substs, kind);
335+
}
336+
}
337+
next_param = params.next();
329338
}
339+
(None, None) => break,
340+
}
341+
if progress_arg {
342+
next_arg = args.next();
330343
}
331-
next_param = params.next();
332344
}
333345
}
334346

0 commit comments

Comments
 (0)