@@ -599,8 +599,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
599
599
format ! ( "the explicit type `{}`, with the {} parameters specified" , ty, param_type)
600
600
}
601
601
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 ( ) ;
604
604
let ty = ty_to_string ( ty) ;
605
605
format ! (
606
606
"the explicit type `{}`, where the {} parameter `{}` is specified" ,
@@ -910,7 +910,7 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
910
910
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > {
911
911
self . tcx
912
912
}
913
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
913
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
914
914
self . level += 1 ;
915
915
let t = match t. kind ( ) {
916
916
// 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> {
919
919
// Account for params with default values, like `Vec`, where we
920
920
// want to show `Vec<T>`, not `Vec<T, _>`. If we replaced that
921
921
// subst, then we'd get the incorrect output, so we passthrough.
922
- let substs: Vec < _ > = substs
922
+ let substs = substs
923
923
. iter ( )
924
924
. zip ( generics. params . iter ( ) )
925
925
. 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) ,
927
927
( 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 ( ) )
929
929
}
930
930
_ => subst. super_fold_with ( self ) ,
931
931
} )
932
- . collect ( ) ;
932
+ . collect :: < Result < Vec < _ > , ! > > ( ) ? ;
933
933
let should_keep = |subst : & GenericArg < ' _ > | match subst. unpack ( ) {
934
934
ty:: subst:: GenericArgKind :: Type ( t) => match t. kind ( ) {
935
935
ty:: Error ( _) => false ,
@@ -948,11 +948,11 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
948
948
}
949
949
}
950
950
ty:: Ref ( _, ty, _) => {
951
- let ty = self . fold_ty ( ty) ;
951
+ let ty = self . fold_ty ( ty) ? ;
952
952
match ty. kind ( ) {
953
953
// Avoid `&_`, these can be safely presented as `_`.
954
954
ty:: Error ( _) => self . tcx ( ) . ty_error ( ) ,
955
- _ => t. super_fold_with ( self ) ,
955
+ _ => t. super_fold_with ( self ) ? ,
956
956
}
957
957
}
958
958
// 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> {
963
963
| ty:: FnPtr ( _)
964
964
| ty:: Opaque ( ..)
965
965
| 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
+ ) ) ,
970
971
// We don't want to hide type params that haven't been resolved yet.
971
972
// This would be the type that will be written out with the type param
972
973
// name in the output.
973
974
ty:: Infer ( _) => t,
974
975
// 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 ) ? ,
976
977
// Hide this type
977
978
_ => self . tcx ( ) . ty_error ( ) ,
978
979
} ;
979
980
self . level -= 1 ;
980
- t
981
+ Ok ( t )
981
982
}
982
983
}
983
984
@@ -987,9 +988,9 @@ impl<'tcx> TypeFolder<'tcx> for ErrTypeParamEraser<'tcx> {
987
988
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > {
988
989
self . 0
989
990
}
990
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
991
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
991
992
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 ) ) ) ,
993
994
_ => t. super_fold_with ( self ) ,
994
995
}
995
996
}
0 commit comments