@@ -267,29 +267,33 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
267
267
268
268
// Check whether this segment takes generic arguments and the user has provided any.
269
269
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 {
271
275
// We're going to iterate through the generic arguments that the user
272
276
// provided, matching them with the generic parameters we expect.
273
277
// Mismatches can occur as a result of elided lifetimes, or for malformed
274
278
// 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) ) => {
277
282
match ( & param. kind , arg) {
278
283
( GenericParamDefKind :: Lifetime , GenericArg :: Lifetime ( _) ) => {
279
284
push_kind ( & mut substs, provided_kind ( param, arg) ) ;
280
285
next_param = params. next ( ) ;
281
- continue ' args;
282
286
}
283
287
( GenericParamDefKind :: Lifetime , GenericArg :: Type ( _) ) => {
284
288
// We expected a lifetime argument, but got a type
285
289
// argument. That means we're inferring the lifetimes.
286
290
push_kind ( & mut substs, inferred_kind ( None , param, infer_types) ) ;
287
291
next_param = params. next ( ) ;
292
+ progress_arg = false ;
288
293
}
289
294
( GenericParamDefKind :: Type { .. } , GenericArg :: Type ( _) ) => {
290
295
push_kind ( & mut substs, provided_kind ( param, arg) ) ;
291
296
next_param = params. next ( ) ;
292
- continue ' args;
293
297
}
294
298
( GenericParamDefKind :: Type { .. } , GenericArg :: Lifetime ( _) ) => {
295
299
// We expected a type argument, but got a lifetime
@@ -300,35 +304,43 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
300
304
if err_if_invalid {
301
305
tcx. sess . delay_span_bug ( span,
302
306
"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 ( ) ;
304
312
}
305
- break ' args;
306
313
}
307
314
}
308
315
}
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
+ }
325
324
}
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 ( ) ;
329
338
}
339
+ ( None , None ) => break ,
340
+ }
341
+ if progress_arg {
342
+ next_arg = args. next ( ) ;
330
343
}
331
- next_param = params. next ( ) ;
332
344
}
333
345
}
334
346
0 commit comments