@@ -408,34 +408,13 @@ fn create_substs_for_ast_path<'tcx>(
408
408
. take_while ( |x| x. default . is_none ( ) )
409
409
. count ( ) ;
410
410
411
- // Fill with `ty_infer` if no params were specified, as long as
412
- // they were optional (e.g. paths inside expressions).
413
- let mut type_substs = if param_mode == PathParamMode :: Optional &&
414
- types_provided. is_empty ( ) {
415
- fn default_type_parameter < ' tcx > ( p : & ty:: TypeParameterDef < ' tcx > , self_ty : Option < Ty < ' tcx > > )
416
- -> Option < ty:: TypeParameterDef < ' tcx > >
417
- {
418
- if let Some ( ref default) = p. default {
419
- if self_ty. is_none ( ) && default. has_self_ty ( ) {
420
- // There is no suitable inference default for a type parameter
421
- // that references self with no self-type provided.
422
- return None ;
423
- }
424
- }
425
-
426
- Some ( p. clone ( ) )
427
- }
428
-
429
- let mut substs = region_substs. clone ( ) ;
430
-
431
- ty_param_defs
432
- . iter ( )
433
- . map ( |p| this. ty_infer ( default_type_parameter ( p, self_ty) , Some ( & mut substs) ,
434
- Some ( TypeSpace ) , span) )
435
- . collect ( )
436
- } else {
437
- types_provided
438
- } ;
411
+ let mut type_substs = get_type_substs_for_defs ( this,
412
+ span,
413
+ types_provided,
414
+ param_mode,
415
+ ty_param_defs,
416
+ region_substs. clone ( ) ,
417
+ self_ty) ;
439
418
440
419
let supplied_ty_param_count = type_substs. len ( ) ;
441
420
check_type_argument_count ( this. tcx ( ) , span, supplied_ty_param_count,
@@ -499,6 +478,42 @@ fn create_substs_for_ast_path<'tcx>(
499
478
substs
500
479
}
501
480
481
+ /// Returns types_provided if it is not empty, otherwise populating the
482
+ /// type parameters with inference variables as appropriate.
483
+ fn get_type_substs_for_defs < ' tcx > ( this : & AstConv < ' tcx > ,
484
+ span : Span ,
485
+ types_provided : Vec < Ty < ' tcx > > ,
486
+ param_mode : PathParamMode ,
487
+ ty_param_defs : & [ ty:: TypeParameterDef < ' tcx > ] ,
488
+ mut substs : Substs < ' tcx > ,
489
+ self_ty : Option < Ty < ' tcx > > )
490
+ -> Vec < Ty < ' tcx > >
491
+ {
492
+ fn default_type_parameter < ' tcx > ( p : & ty:: TypeParameterDef < ' tcx > , self_ty : Option < Ty < ' tcx > > )
493
+ -> Option < ty:: TypeParameterDef < ' tcx > >
494
+ {
495
+ if let Some ( ref default) = p. default {
496
+ if self_ty. is_none ( ) && default. has_self_ty ( ) {
497
+ // There is no suitable inference default for a type parameter
498
+ // that references self with no self-type provided.
499
+ return None ;
500
+ }
501
+ }
502
+
503
+ Some ( p. clone ( ) )
504
+ }
505
+
506
+ if param_mode == PathParamMode :: Optional && types_provided. is_empty ( ) {
507
+ ty_param_defs
508
+ . iter ( )
509
+ . map ( |p| this. ty_infer ( default_type_parameter ( p, self_ty) , Some ( & mut substs) ,
510
+ Some ( TypeSpace ) , span) )
511
+ . collect ( )
512
+ } else {
513
+ types_provided
514
+ }
515
+ }
516
+
502
517
struct ConvertedBinding < ' tcx > {
503
518
item_name : ast:: Name ,
504
519
ty : Ty < ' tcx > ,
0 commit comments