@@ -216,7 +216,22 @@ pub fn normalize<'a, 'b, 'tcx, T>(
216216where
217217 T : TypeFoldable < ' tcx > ,
218218{
219- normalize_with_depth ( selcx, param_env, cause, 0 , value)
219+ let mut obligations = Vec :: new ( ) ;
220+ let value = normalize_to ( selcx, param_env, cause, value, & mut obligations) ;
221+ Normalized { value, obligations }
222+ }
223+
224+ pub fn normalize_to < ' a , ' b , ' tcx , T > (
225+ selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
226+ param_env : ty:: ParamEnv < ' tcx > ,
227+ cause : ObligationCause < ' tcx > ,
228+ value : & T ,
229+ obligations : & mut Vec < PredicateObligation < ' tcx > > ,
230+ ) -> T
231+ where
232+ T : TypeFoldable < ' tcx > ,
233+ {
234+ normalize_with_depth_to ( selcx, param_env, cause, 0 , value, obligations)
220235}
221236
222237/// As `normalize`, but with a custom depth.
@@ -227,11 +242,27 @@ pub fn normalize_with_depth<'a, 'b, 'tcx, T>(
227242 depth : usize ,
228243 value : & T ,
229244) -> Normalized < ' tcx , T >
245+ where
246+ T : TypeFoldable < ' tcx > ,
247+ {
248+ let mut obligations = Vec :: new ( ) ;
249+ let value = normalize_with_depth_to ( selcx, param_env, cause, depth, value, & mut obligations) ;
250+ Normalized { value, obligations }
251+ }
252+
253+ pub fn normalize_with_depth_to < ' a , ' b , ' tcx , T > (
254+ selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
255+ param_env : ty:: ParamEnv < ' tcx > ,
256+ cause : ObligationCause < ' tcx > ,
257+ depth : usize ,
258+ value : & T ,
259+ obligations : & mut Vec < PredicateObligation < ' tcx > > ,
260+ ) -> T
230261where
231262 T : TypeFoldable < ' tcx > ,
232263{
233264 debug ! ( "normalize_with_depth(depth={}, value={:?})" , depth, value) ;
234- let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth) ;
265+ let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth, obligations ) ;
235266 let result = normalizer. fold ( value) ;
236267 debug ! (
237268 "normalize_with_depth: depth={} result={:?} with {} obligations" ,
@@ -240,14 +271,14 @@ where
240271 normalizer. obligations. len( )
241272 ) ;
242273 debug ! ( "normalize_with_depth: depth={} obligations={:?}" , depth, normalizer. obligations) ;
243- Normalized { value : result, obligations : normalizer . obligations }
274+ result
244275}
245276
246277struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
247278 selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
248279 param_env : ty:: ParamEnv < ' tcx > ,
249280 cause : ObligationCause < ' tcx > ,
250- obligations : Vec < PredicateObligation < ' tcx > > ,
281+ obligations : & ' a mut Vec < PredicateObligation < ' tcx > > ,
251282 depth : usize ,
252283}
253284
@@ -257,8 +288,9 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
257288 param_env : ty:: ParamEnv < ' tcx > ,
258289 cause : ObligationCause < ' tcx > ,
259290 depth : usize ,
291+ obligations : & ' a mut Vec < PredicateObligation < ' tcx > > ,
260292 ) -> AssocTypeNormalizer < ' a , ' b , ' tcx > {
261- AssocTypeNormalizer { selcx, param_env, cause, obligations : vec ! [ ] , depth }
293+ AssocTypeNormalizer { selcx, param_env, cause, obligations, depth }
262294 }
263295
264296 fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : & T ) -> T {
@@ -343,7 +375,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
343375 ) ;
344376 debug ! (
345377 "AssocTypeNormalizer: depth={} normalized {:?} to {:?}, \
346- now with {} obligations",
378+ now with {} obligations",
347379 self . depth,
348380 ty,
349381 normalized_ty,
@@ -441,8 +473,8 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
441473
442474 debug ! (
443475 "opt_normalize_projection_type(\
444- projection_ty={:?}, \
445- depth={})",
476+ projection_ty={:?}, \
477+ depth={})",
446478 projection_ty, depth
447479 ) ;
448480
@@ -469,7 +501,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
469501 // changes
470502 debug ! (
471503 "opt_normalize_projection_type: \
472- found cache entry: ambiguous"
504+ found cache entry: ambiguous"
473505 ) ;
474506 if !projection_ty. has_closure_types ( ) {
475507 return None ;
@@ -498,7 +530,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
498530
499531 debug ! (
500532 "opt_normalize_projection_type: \
501- found cache entry: in-progress"
533+ found cache entry: in-progress"
502534 ) ;
503535
504536 // But for now, let's classify this as an overflow:
@@ -521,7 +553,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
521553 // evaluations can causes ICEs (e.g., #43132).
522554 debug ! (
523555 "opt_normalize_projection_type: \
524- found normalized ty `{:?}`",
556+ found normalized ty `{:?}`",
525557 ty
526558 ) ;
527559
@@ -546,7 +578,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
546578 Err ( ProjectionCacheEntry :: Error ) => {
547579 debug ! (
548580 "opt_normalize_projection_type: \
549- found error"
581+ found error"
550582 ) ;
551583 let result = normalize_to_error ( selcx, param_env, projection_ty, cause, depth) ;
552584 obligations. extend ( result. obligations ) ;
@@ -567,23 +599,28 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
567599
568600 debug ! (
569601 "opt_normalize_projection_type: \
570- projected_ty={:?} \
571- depth={} \
572- projected_obligations={:?}",
602+ projected_ty={:?} \
603+ depth={} \
604+ projected_obligations={:?}",
573605 projected_ty, depth, projected_obligations
574606 ) ;
575607
576608 let result = if projected_ty. has_projections ( ) {
577- let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth + 1 ) ;
609+ let mut normalizer = AssocTypeNormalizer :: new (
610+ selcx,
611+ param_env,
612+ cause,
613+ depth + 1 ,
614+ & mut projected_obligations,
615+ ) ;
578616 let normalized_ty = normalizer. fold ( & projected_ty) ;
579617
580618 debug ! (
581619 "opt_normalize_projection_type: \
582- normalized_ty={:?} depth={}",
620+ normalized_ty={:?} depth={}",
583621 normalized_ty, depth
584622 ) ;
585623
586- projected_obligations. extend ( normalizer. obligations ) ;
587624 Normalized { value : normalized_ty, obligations : projected_obligations }
588625 } else {
589626 Normalized { value : projected_ty, obligations : projected_obligations }
@@ -597,7 +634,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
597634 Ok ( ProjectedTy :: NoProgress ( projected_ty) ) => {
598635 debug ! (
599636 "opt_normalize_projection_type: \
600- projected_ty={:?} no progress",
637+ projected_ty={:?} no progress",
601638 projected_ty
602639 ) ;
603640 let result = Normalized { value : projected_ty, obligations : vec ! [ ] } ;
@@ -608,7 +645,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
608645 Err ( ProjectionTyError :: TooManyCandidates ) => {
609646 debug ! (
610647 "opt_normalize_projection_type: \
611- too many candidates"
648+ too many candidates"
612649 ) ;
613650 infcx. projection_cache . borrow_mut ( ) . ambiguous ( cache_key) ;
614651 None
@@ -930,7 +967,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx, I>(
930967
931968 debug ! (
932969 "assemble_candidates_from_predicates: candidate={:?} \
933- is_match={} same_def_id={}",
970+ is_match={} same_def_id={}",
934971 data, is_match, same_def_id
935972 ) ;
936973
@@ -1192,7 +1229,7 @@ fn confirm_object_candidate<'cx, 'tcx>(
11921229 None => {
11931230 debug ! (
11941231 "confirm_object_candidate: no env-predicate \
1195- found in object type `{:?}`; ill-formed",
1232+ found in object type `{:?}`; ill-formed",
11961233 object_ty
11971234 ) ;
11981235 return Progress :: error ( selcx. tcx ( ) ) ;
0 commit comments