@@ -61,7 +61,6 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
6161 cause : self . cause ,
6262 param_env : self . param_env ,
6363 obligations : vec ! [ ] ,
64- error : false ,
6564 cache : SsoHashMap :: new ( ) ,
6665 anon_depth : 0 ,
6766 universes : vec ! [ ] ,
@@ -88,7 +87,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
8887 normalizer. universes . extend ( ( 0 ..max_visitor. escaping ) . map ( |_| None ) ) ;
8988 }
9089 }
91- let result = value. fold_with ( & mut normalizer) . into_ok ( ) ;
90+ let result = value. fold_with ( & mut normalizer) ;
9291 info ! (
9392 "normalize::<{}>: result={:?} with {} obligations" ,
9493 std:: any:: type_name:: <T >( ) ,
@@ -100,11 +99,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
10099 std:: any:: type_name:: <T >( ) ,
101100 normalizer. obligations,
102101 ) ;
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 } )
108103 }
109104}
110105
@@ -171,12 +166,13 @@ struct QueryNormalizer<'cx, 'tcx> {
171166 param_env : ty:: ParamEnv < ' tcx > ,
172167 obligations : Vec < PredicateObligation < ' tcx > > ,
173168 cache : SsoHashMap < Ty < ' tcx > , Ty < ' tcx > > ,
174- error : bool ,
175169 anon_depth : usize ,
176170 universes : Vec < Option < ty:: UniverseIndex > > ,
177171}
178172
179173impl < ' cx , ' tcx > TypeFolder < ' tcx > for QueryNormalizer < ' cx , ' tcx > {
174+ type Error = NoSolution ;
175+
180176 fn tcx < ' c > ( & ' c self ) -> TyCtxt < ' tcx > {
181177 self . infcx . tcx
182178 }
@@ -262,39 +258,22 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
262258 . canonicalize_query_keep_static ( self . param_env . and ( data) , & mut orig_values) ;
263259 debug ! ( "QueryNormalizer: c_data = {:#?}" , c_data) ;
264260 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 ) ;
297265 }
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 )
298277 }
299278
300279 ty:: Projection ( data) => {
@@ -318,43 +297,29 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
318297 . canonicalize_query_keep_static ( self . param_env . and ( data) , & mut orig_values) ;
319298 debug ! ( "QueryNormalizer: c_data = {:#?}" , c_data) ;
320299 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 ) ;
357304 }
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+ ) )
358323 }
359324
360325 _ => ty. super_fold_with ( self ) ,
0 commit comments