@@ -599,8 +599,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
599599 format ! ( "the explicit type `{}`, with the {} parameters specified" , ty, param_type)
600600 }
601601 Some ( ty) if is_named_and_not_impl_trait ( ty) && ty. to_string ( ) != arg_data. name => {
602- let ty = ResolvedTypeParamEraser :: new ( self . tcx ) . fold_ty ( ty) ;
603- let ty = ErrTypeParamEraser ( self . tcx ) . fold_ty ( ty) ;
602+ let ty = ResolvedTypeParamEraser :: new ( self . tcx ) . fold_ty ( ty) . unwrap ( ) ;
603+ let ty = ErrTypeParamEraser ( self . tcx ) . fold_ty ( ty) . unwrap ( ) ;
604604 let ty = ty_to_string ( ty) ;
605605 format ! (
606606 "the explicit type `{}`, where the {} parameter `{}` is specified" ,
@@ -910,7 +910,7 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
910910 fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > {
911911 self . tcx
912912 }
913- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
913+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
914914 self . level += 1 ;
915915 let t = match t. kind ( ) {
916916 // We'll hide this type only if all its type params are hidden as well.
@@ -919,17 +919,17 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
919919 // Account for params with default values, like `Vec`, where we
920920 // want to show `Vec<T>`, not `Vec<T, _>`. If we replaced that
921921 // subst, then we'd get the incorrect output, so we passthrough.
922- let substs: Vec < _ > = substs
922+ let substs = substs
923923 . iter ( )
924924 . zip ( generics. params . iter ( ) )
925925 . map ( |( subst, param) | match & ( subst. unpack ( ) , & param. kind ) {
926- ( _, ty:: GenericParamDefKind :: Type { has_default : true , .. } ) => subst,
926+ ( _, ty:: GenericParamDefKind :: Type { has_default : true , .. } ) => Ok ( subst) ,
927927 ( crate :: infer:: GenericArgKind :: Const ( c) , _) => {
928- self . replace_infers ( c, param. index , param. name ) . into ( )
928+ Ok ( self . replace_infers ( c, param. index , param. name ) . into ( ) )
929929 }
930930 _ => subst. super_fold_with ( self ) ,
931931 } )
932- . collect ( ) ;
932+ . collect :: < Result < Vec < _ > , ! > > ( ) ? ;
933933 let should_keep = |subst : & GenericArg < ' _ > | match subst. unpack ( ) {
934934 ty:: subst:: GenericArgKind :: Type ( t) => match t. kind ( ) {
935935 ty:: Error ( _) => false ,
@@ -948,11 +948,11 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
948948 }
949949 }
950950 ty:: Ref ( _, ty, _) => {
951- let ty = self . fold_ty ( ty) ;
951+ let ty = self . fold_ty ( ty) ? ;
952952 match ty. kind ( ) {
953953 // Avoid `&_`, these can be safely presented as `_`.
954954 ty:: Error ( _) => self . tcx ( ) . ty_error ( ) ,
955- _ => t. super_fold_with ( self ) ,
955+ _ => t. super_fold_with ( self ) ? ,
956956 }
957957 }
958958 // We could account for `()` if we wanted to replace it, but it's assured to be short.
@@ -963,21 +963,22 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
963963 | ty:: FnPtr ( _)
964964 | ty:: Opaque ( ..)
965965 | ty:: Projection ( _)
966- | ty:: Never => t. super_fold_with ( self ) ,
967- ty:: Array ( ty, c) => self
968- . tcx ( )
969- . mk_ty ( ty:: Array ( self . fold_ty ( ty) , self . replace_infers ( c, 0 , Symbol :: intern ( "N" ) ) ) ) ,
966+ | ty:: Never => t. super_fold_with ( self ) ?,
967+ ty:: Array ( ty, c) => self . tcx ( ) . mk_ty ( ty:: Array (
968+ self . fold_ty ( ty) ?,
969+ self . replace_infers ( c, 0 , Symbol :: intern ( "N" ) ) ,
970+ ) ) ,
970971 // We don't want to hide type params that haven't been resolved yet.
971972 // This would be the type that will be written out with the type param
972973 // name in the output.
973974 ty:: Infer ( _) => t,
974975 // We don't want to hide the outermost type, only its type params.
975- _ if self . level == 1 => t. super_fold_with ( self ) ,
976+ _ if self . level == 1 => t. super_fold_with ( self ) ? ,
976977 // Hide this type
977978 _ => self . tcx ( ) . ty_error ( ) ,
978979 } ;
979980 self . level -= 1 ;
980- t
981+ Ok ( t )
981982 }
982983}
983984
@@ -987,9 +988,9 @@ impl<'tcx> TypeFolder<'tcx> for ErrTypeParamEraser<'tcx> {
987988 fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > {
988989 self . 0
989990 }
990- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
991+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
991992 match t. kind ( ) {
992- ty:: Error ( _) => self . tcx ( ) . mk_ty_var ( ty:: TyVid :: from_u32 ( 0 ) ) ,
993+ ty:: Error ( _) => Ok ( self . tcx ( ) . mk_ty_var ( ty:: TyVid :: from_u32 ( 0 ) ) ) ,
993994 _ => t. super_fold_with ( self ) ,
994995 }
995996 }
0 commit comments