@@ -245,7 +245,7 @@ pub trait GenericArgsLowerer<'a, 'tcx> {
245245
246246 fn inferred_kind (
247247 & mut self ,
248- args : Option < & [ ty:: GenericArg < ' tcx > ] > ,
248+ preceding_args : & [ ty:: GenericArg < ' tcx > ] ,
249249 param : & ty:: GenericParamDef ,
250250 infer_args : bool ,
251251 ) -> ty:: GenericArg < ' tcx > ;
@@ -525,30 +525,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
525525
526526 fn inferred_kind (
527527 & mut self ,
528- args : Option < & [ ty:: GenericArg < ' tcx > ] > ,
528+ preceding_args : & [ ty:: GenericArg < ' tcx > ] ,
529529 param : & ty:: GenericParamDef ,
530530 infer_args : bool ,
531531 ) -> ty:: GenericArg < ' tcx > {
532532 let tcx = self . lowerer . tcx ( ) ;
533533
534534 if let Err ( incorrect) = self . incorrect_args {
535535 if incorrect. invalid_args . contains ( & ( param. index as usize ) ) {
536- // FIXME: use `param.to_error` once `inferred_kind` is supplied a list of
537- // all previous generic args.
538- return match param. kind {
539- GenericParamDefKind :: Lifetime => {
540- ty:: Region :: new_error ( tcx, incorrect. reported ) . into ( )
541- }
542- GenericParamDefKind :: Type { .. } => {
543- Ty :: new_error ( tcx, incorrect. reported ) . into ( )
544- }
545- GenericParamDefKind :: Const { .. } => ty:: Const :: new_error (
546- tcx,
547- incorrect. reported ,
548- Ty :: new_error ( tcx, incorrect. reported ) ,
549- )
550- . into ( ) ,
551- } ;
536+ return param. to_error ( tcx, preceding_args) ;
552537 }
553538 }
554539 match param. kind {
@@ -569,15 +554,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
569554 GenericParamDefKind :: Type { has_default, .. } => {
570555 if !infer_args && has_default {
571556 // No type parameter provided, but a default exists.
572- let args = args. unwrap ( ) ;
573- if args. iter ( ) . any ( |arg| match arg. unpack ( ) {
574- GenericArgKind :: Type ( ty) => ty. references_error ( ) ,
575- _ => false ,
576- } ) {
557+ if let Some ( prev) =
558+ preceding_args. iter ( ) . find_map ( |arg| match arg. unpack ( ) {
559+ GenericArgKind :: Type ( ty) => ty. error_reported ( ) . err ( ) ,
560+ _ => None ,
561+ } )
562+ {
577563 // Avoid ICE #86756 when type error recovery goes awry.
578- return Ty :: new_misc_error ( tcx) . into ( ) ;
564+ return Ty :: new_error ( tcx, prev ) . into ( ) ;
579565 }
580- tcx. at ( self . span ) . type_of ( param. def_id ) . instantiate ( tcx, args) . into ( )
566+ tcx. at ( self . span )
567+ . type_of ( param. def_id )
568+ . instantiate ( tcx, preceding_args)
569+ . into ( )
581570 } else if infer_args {
582571 self . lowerer . ty_infer ( Some ( param) , self . span ) . into ( )
583572 } else {
@@ -597,7 +586,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
597586 // FIXME(effects) see if we should special case effect params here
598587 if !infer_args && has_default {
599588 tcx. const_param_default ( param. def_id )
600- . instantiate ( tcx, args . unwrap ( ) )
589+ . instantiate ( tcx, preceding_args )
601590 . into ( )
602591 } else {
603592 if infer_args {
0 commit comments