@@ -414,34 +414,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
414
414
arg : & GenericArg < ' _ > ,
415
415
) -> subst:: GenericArg < ' tcx > {
416
416
let tcx = self . astconv . tcx ( ) ;
417
+
418
+ let mut handle_ty_args = |has_default, ty : & hir:: Ty < ' _ > | {
419
+ if has_default {
420
+ tcx. check_optional_stability (
421
+ param. def_id ,
422
+ Some ( arg. id ( ) ) ,
423
+ arg. span ( ) ,
424
+ None ,
425
+ |_, _| {
426
+ // Default generic parameters may not be marked
427
+ // with stability attributes, i.e. when the
428
+ // default parameter was defined at the same time
429
+ // as the rest of the type. As such, we ignore missing
430
+ // stability attributes.
431
+ } ,
432
+ )
433
+ }
434
+ if let ( hir:: TyKind :: Infer , false ) = ( & ty. kind , self . astconv . allow_ty_infer ( ) ) {
435
+ self . inferred_params . push ( ty. span ) ;
436
+ tcx. ty_error ( ) . into ( )
437
+ } else {
438
+ self . astconv . ast_ty_to_ty ( ty) . into ( )
439
+ }
440
+ } ;
441
+
417
442
match ( & param. kind , arg) {
418
443
( GenericParamDefKind :: Lifetime , GenericArg :: Lifetime ( lt) ) => {
419
444
self . astconv . ast_region_to_region ( lt, Some ( param) ) . into ( )
420
445
}
421
446
( & GenericParamDefKind :: Type { has_default, .. } , GenericArg :: Type ( ty) ) => {
422
- if has_default {
423
- tcx. check_optional_stability (
424
- param. def_id ,
425
- Some ( arg. id ( ) ) ,
426
- arg. span ( ) ,
427
- None ,
428
- |_, _| {
429
- // Default generic parameters may not be marked
430
- // with stability attributes, i.e. when the
431
- // default parameter was defined at the same time
432
- // as the rest of the type. As such, we ignore missing
433
- // stability attributes.
434
- } ,
435
- )
436
- }
437
- if let ( hir:: TyKind :: Infer , false ) =
438
- ( & ty. kind , self . astconv . allow_ty_infer ( ) )
439
- {
440
- self . inferred_params . push ( ty. span ) ;
441
- tcx. ty_error ( ) . into ( )
442
- } else {
443
- self . astconv . ast_ty_to_ty ( ty) . into ( )
444
- }
447
+ handle_ty_args ( has_default, ty)
448
+ }
449
+ ( & GenericParamDefKind :: Type { has_default, .. } , GenericArg :: Infer ( inf) ) => {
450
+ handle_ty_args ( has_default, & inf. to_ty ( ) )
445
451
}
446
452
( GenericParamDefKind :: Const { .. } , GenericArg :: Const ( ct) ) => {
447
453
ty:: Const :: from_opt_const_arg_anon_const (
@@ -453,41 +459,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
453
459
)
454
460
. into ( )
455
461
}
456
- ( & GenericParamDefKind :: Const { has_default } , hir:: GenericArg :: Infer ( inf) ) => {
457
- if has_default {
458
- tcx. const_param_default ( param. def_id ) . into ( )
459
- } else if self . astconv . allow_ty_infer ( ) {
460
- // FIXME(const_generics): Actually infer parameter here?
461
- todo ! ( )
462
- } else {
463
- self . inferred_params . push ( inf. span ) ;
464
- tcx. ty_error ( ) . into ( )
465
- }
466
- }
467
- (
468
- & GenericParamDefKind :: Type { has_default, .. } ,
469
- hir:: GenericArg :: Infer ( inf) ,
470
- ) => {
471
- if has_default {
472
- tcx. check_optional_stability (
473
- param. def_id ,
474
- Some ( arg. id ( ) ) ,
475
- arg. span ( ) ,
476
- None ,
477
- |_, _| {
478
- // Default generic parameters may not be marked
479
- // with stability attributes, i.e. when the
480
- // default parameter was defined at the same time
481
- // as the rest of the type. As such, we ignore missing
482
- // stability attributes.
483
- } ,
484
- ) ;
485
- }
462
+ ( & GenericParamDefKind :: Const { .. } , hir:: GenericArg :: Infer ( inf) ) => {
463
+ let ty = tcx. at ( self . span ) . type_of ( param. def_id ) ;
486
464
if self . astconv . allow_ty_infer ( ) {
487
- self . astconv . ast_ty_to_ty ( & inf . to_ty ( ) ) . into ( )
465
+ self . astconv . ct_infer ( ty , Some ( param ) , inf . span ) . into ( )
488
466
} else {
489
467
self . inferred_params . push ( inf. span ) ;
490
- tcx. ty_error ( ) . into ( )
468
+ tcx. const_error ( ty ) . into ( )
491
469
}
492
470
}
493
471
_ => unreachable ! ( ) ,
0 commit comments