@@ -61,7 +61,6 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
61
61
cause : self . cause ,
62
62
param_env : self . param_env ,
63
63
obligations : vec ! [ ] ,
64
- error : false ,
65
64
cache : SsoHashMap :: new ( ) ,
66
65
anon_depth : 0 ,
67
66
universes : vec ! [ ] ,
@@ -88,7 +87,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
88
87
normalizer. universes . extend ( ( 0 ..max_visitor. escaping ) . map ( |_| None ) ) ;
89
88
}
90
89
}
91
- let result = value. fold_with ( & mut normalizer) . into_ok ( ) ;
90
+ let result = value. fold_with ( & mut normalizer) ;
92
91
info ! (
93
92
"normalize::<{}>: result={:?} with {} obligations" ,
94
93
std:: any:: type_name:: <T >( ) ,
@@ -100,11 +99,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
100
99
std:: any:: type_name:: <T >( ) ,
101
100
normalizer. obligations,
102
101
) ;
103
- if normalizer. error {
104
- Err ( NoSolution )
105
- } else {
106
- Ok ( Normalized { value : result, obligations : normalizer. obligations } )
107
- }
102
+ result. map ( |value| Normalized { value, obligations : normalizer. obligations } )
108
103
}
109
104
}
110
105
@@ -171,12 +166,13 @@ struct QueryNormalizer<'cx, 'tcx> {
171
166
param_env : ty:: ParamEnv < ' tcx > ,
172
167
obligations : Vec < PredicateObligation < ' tcx > > ,
173
168
cache : SsoHashMap < Ty < ' tcx > , Ty < ' tcx > > ,
174
- error : bool ,
175
169
anon_depth : usize ,
176
170
universes : Vec < Option < ty:: UniverseIndex > > ,
177
171
}
178
172
179
173
impl < ' cx , ' tcx > TypeFolder < ' tcx > for QueryNormalizer < ' cx , ' tcx > {
174
+ type Error = NoSolution ;
175
+
180
176
fn tcx < ' c > ( & ' c self ) -> TyCtxt < ' tcx > {
181
177
self . infcx . tcx
182
178
}
@@ -262,39 +258,22 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
262
258
. canonicalize_query_keep_static ( self . param_env . and ( data) , & mut orig_values) ;
263
259
debug ! ( "QueryNormalizer: c_data = {:#?}" , c_data) ;
264
260
debug ! ( "QueryNormalizer: orig_values = {:#?}" , orig_values) ;
265
- match tcx. normalize_projection_ty ( c_data) {
266
- Ok ( result) => {
267
- // We don't expect ambiguity.
268
- if result. is_ambiguous ( ) {
269
- self . error = true ;
270
- return ty. super_fold_with ( self ) ;
271
- }
272
-
273
- match self . infcx . instantiate_query_response_and_region_obligations (
274
- self . cause ,
275
- self . param_env ,
276
- & orig_values,
277
- result,
278
- ) {
279
- Ok ( InferOk { value : result, obligations } ) => {
280
- debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
281
- debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
282
- self . obligations . extend ( obligations) ;
283
- Ok ( result. normalized_ty )
284
- }
285
-
286
- Err ( _) => {
287
- self . error = true ;
288
- ty. super_fold_with ( self )
289
- }
290
- }
291
- }
292
-
293
- Err ( NoSolution ) => {
294
- self . error = true ;
295
- ty. super_fold_with ( self )
296
- }
261
+ let result = tcx. normalize_projection_ty ( c_data) ?;
262
+ // We don't expect ambiguity.
263
+ if result. is_ambiguous ( ) {
264
+ return Err ( NoSolution ) ;
297
265
}
266
+ let InferOk { value : result, obligations } =
267
+ self . infcx . instantiate_query_response_and_region_obligations (
268
+ self . cause ,
269
+ self . param_env ,
270
+ & orig_values,
271
+ result,
272
+ ) ?;
273
+ debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
274
+ debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
275
+ self . obligations . extend ( obligations) ;
276
+ Ok ( result. normalized_ty )
298
277
}
299
278
300
279
ty:: Projection ( data) => {
@@ -318,43 +297,29 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
318
297
. canonicalize_query_keep_static ( self . param_env . and ( data) , & mut orig_values) ;
319
298
debug ! ( "QueryNormalizer: c_data = {:#?}" , c_data) ;
320
299
debug ! ( "QueryNormalizer: orig_values = {:#?}" , orig_values) ;
321
- match tcx. normalize_projection_ty ( c_data) {
322
- Ok ( result) => {
323
- // We don't expect ambiguity.
324
- if result. is_ambiguous ( ) {
325
- self . error = true ;
326
- return ty. super_fold_with ( self ) ;
327
- }
328
- match self . infcx . instantiate_query_response_and_region_obligations (
329
- self . cause ,
330
- self . param_env ,
331
- & orig_values,
332
- result,
333
- ) {
334
- Ok ( InferOk { value : result, obligations } ) => {
335
- debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
336
- debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
337
- self . obligations . extend ( obligations) ;
338
- Ok ( crate :: traits:: project:: PlaceholderReplacer :: replace_placeholders (
339
- infcx,
340
- mapped_regions,
341
- mapped_types,
342
- mapped_consts,
343
- & self . universes ,
344
- result. normalized_ty ,
345
- ) )
346
- }
347
- Err ( _) => {
348
- self . error = true ;
349
- ty. super_fold_with ( self )
350
- }
351
- }
352
- }
353
- Err ( NoSolution ) => {
354
- self . error = true ;
355
- ty. super_fold_with ( self )
356
- }
300
+ let result = tcx. normalize_projection_ty ( c_data) ?;
301
+ // We don't expect ambiguity.
302
+ if result. is_ambiguous ( ) {
303
+ return Err ( NoSolution ) ;
357
304
}
305
+ let InferOk { value : result, obligations } =
306
+ self . infcx . instantiate_query_response_and_region_obligations (
307
+ self . cause ,
308
+ self . param_env ,
309
+ & orig_values,
310
+ result,
311
+ ) ?;
312
+ debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
313
+ debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
314
+ self . obligations . extend ( obligations) ;
315
+ Ok ( crate :: traits:: project:: PlaceholderReplacer :: replace_placeholders (
316
+ infcx,
317
+ mapped_regions,
318
+ mapped_types,
319
+ mapped_consts,
320
+ & self . universes ,
321
+ result. normalized_ty ,
322
+ ) )
358
323
}
359
324
360
325
_ => ty. super_fold_with ( self ) ,
0 commit comments