@@ -408,18 +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
- let mut substs = region_substs. clone ( ) ;
416
- ty_param_defs
417
- . iter ( )
418
- . map ( |p| this. ty_infer ( Some ( p. clone ( ) ) , Some ( & mut substs) , Some ( TypeSpace ) , span) )
419
- . collect ( )
420
- } else {
421
- types_provided
422
- } ;
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) ;
423
418
424
419
let supplied_ty_param_count = type_substs. len ( ) ;
425
420
check_type_argument_count ( this. tcx ( ) , span, supplied_ty_param_count,
@@ -483,6 +478,42 @@ fn create_substs_for_ast_path<'tcx>(
483
478
substs
484
479
}
485
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
+
486
517
struct ConvertedBinding < ' tcx > {
487
518
item_name : ast:: Name ,
488
519
ty : Ty < ' tcx > ,
0 commit comments