@@ -90,12 +90,7 @@ impl<'tcx> TyCtxt<'tcx> {
9090 Ok ( value)
9191 } else {
9292 let mut folder = TryNormalizeAfterErasingRegionsFolder :: new ( self , param_env) ;
93- let result = value. fold_with ( & mut folder) ;
94-
95- match folder. found_normalization_error ( ) {
96- Some ( e) => Err ( e) ,
97- None => Ok ( result) ,
98- }
93+ value. fold_with ( & mut folder)
9994 }
10095 }
10196
@@ -191,12 +186,11 @@ impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
191186struct TryNormalizeAfterErasingRegionsFolder < ' tcx > {
192187 tcx : TyCtxt < ' tcx > ,
193188 param_env : ty:: ParamEnv < ' tcx > ,
194- normalization_error : Option < NormalizationError < ' tcx > > ,
195189}
196190
197191impl < ' tcx > TryNormalizeAfterErasingRegionsFolder < ' tcx > {
198192 fn new ( tcx : TyCtxt < ' tcx > , param_env : ty:: ParamEnv < ' tcx > ) -> Self {
199- TryNormalizeAfterErasingRegionsFolder { tcx, param_env, normalization_error : None }
193+ TryNormalizeAfterErasingRegionsFolder { tcx, param_env }
200194 }
201195
202196 #[ instrument( skip( self ) , level = "debug" ) ]
@@ -209,47 +203,41 @@ impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> {
209203
210204 self . tcx . try_normalize_generic_arg_after_erasing_regions ( arg)
211205 }
212-
213- pub fn found_normalization_error ( & self ) -> Option < NormalizationError < ' tcx > > {
214- self . normalization_error
215- }
216206}
217207
218208impl TypeFolder < ' tcx > for TryNormalizeAfterErasingRegionsFolder < ' tcx > {
209+ type Error = NormalizationError < ' tcx > ;
210+
219211 fn tcx ( & self ) -> TyCtxt < ' tcx > {
220212 self . tcx
221213 }
222214
223- fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
215+ fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
224216 match self . try_normalize_generic_arg_after_erasing_regions ( ty. into ( ) ) {
225- Ok ( t) => t. expect_ty ( ) ,
226- Err ( _) => {
227- self . normalization_error = Some ( NormalizationError :: Type ( ty) ) ;
228- ty
229- }
217+ Ok ( t) => Ok ( t. expect_ty ( ) ) ,
218+ Err ( _) => Err ( NormalizationError :: Type ( ty) ) ,
230219 }
231220 }
232221
233- fn fold_const ( & mut self , c : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
222+ fn fold_const (
223+ & mut self ,
224+ c : & ' tcx ty:: Const < ' tcx > ,
225+ ) -> Result < & ' tcx ty:: Const < ' tcx > , Self :: Error > {
234226 match self . try_normalize_generic_arg_after_erasing_regions ( c. into ( ) ) {
235- Ok ( t) => t. expect_const ( ) ,
236- Err ( _) => {
237- self . normalization_error = Some ( NormalizationError :: Const ( * c) ) ;
238- c
239- }
227+ Ok ( t) => Ok ( t. expect_const ( ) ) ,
228+ Err ( _) => Err ( NormalizationError :: Const ( * c) ) ,
240229 }
241230 }
242231
243- #[ inline]
244- fn fold_mir_const ( & mut self , c : mir:: ConstantKind < ' tcx > ) -> mir:: ConstantKind < ' tcx > {
232+ fn fold_mir_const (
233+ & mut self ,
234+ c : mir:: ConstantKind < ' tcx > ,
235+ ) -> Result < mir:: ConstantKind < ' tcx > , Self :: Error > {
245236 // FIXME: This *probably* needs canonicalization too!
246237 let arg = self . param_env . and ( c) ;
247238 match self . tcx . try_normalize_mir_const_after_erasing_regions ( arg) {
248- Ok ( c) => c,
249- Err ( _) => {
250- self . normalization_error = Some ( NormalizationError :: ConstantKind ( c) ) ;
251- c
252- }
239+ Ok ( c) => Ok ( c) ,
240+ Err ( _) => Err ( NormalizationError :: ConstantKind ( c) ) ,
253241 }
254242 }
255243}
0 commit comments