@@ -595,7 +595,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
595
595
self . evaluate_predicates_recursively_in_new_solver ( predicates)
596
596
} else {
597
597
let mut result = EvaluatedToOk ;
598
- for obligation in predicates {
598
+ for mut obligation in predicates {
599
+ obligation. set_depth_from_parent ( stack. depth ( ) ) ;
599
600
let eval = self . evaluate_predicate_recursively ( stack, obligation. clone ( ) ) ?;
600
601
if let EvaluatedToErr = eval {
601
602
// fast-path - EvaluatedToErr is the top of the lattice,
@@ -661,12 +662,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
661
662
let p = bound_predicate. rebind ( p) ;
662
663
// Does this code ever run?
663
664
match self . infcx . subtype_predicate ( & obligation. cause , obligation. param_env , p) {
664
- Ok ( Ok ( InferOk { mut obligations, .. } ) ) => {
665
- self . add_depth ( obligations. iter_mut ( ) , obligation. recursion_depth ) ;
666
- self . evaluate_predicates_recursively (
667
- previous_stack,
668
- obligations. into_iter ( ) ,
669
- )
665
+ Ok ( Ok ( InferOk { obligations, .. } ) ) => {
666
+ self . evaluate_predicates_recursively ( previous_stack, obligations)
670
667
}
671
668
Ok ( Err ( _) ) => Ok ( EvaluatedToErr ) ,
672
669
Err ( ..) => Ok ( EvaluatedToAmbig ) ,
@@ -677,12 +674,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
677
674
let p = bound_predicate. rebind ( p) ;
678
675
// Does this code ever run?
679
676
match self . infcx . coerce_predicate ( & obligation. cause , obligation. param_env , p) {
680
- Ok ( Ok ( InferOk { mut obligations, .. } ) ) => {
681
- self . add_depth ( obligations. iter_mut ( ) , obligation. recursion_depth ) ;
682
- self . evaluate_predicates_recursively (
683
- previous_stack,
684
- obligations. into_iter ( ) ,
685
- )
677
+ Ok ( Ok ( InferOk { obligations, .. } ) ) => {
678
+ self . evaluate_predicates_recursively ( previous_stack, obligations)
686
679
}
687
680
Ok ( Err ( _) ) => Ok ( EvaluatedToErr ) ,
688
681
Err ( ..) => Ok ( EvaluatedToAmbig ) ,
@@ -755,9 +748,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
755
748
arg,
756
749
obligation. cause . span ,
757
750
) {
758
- Some ( mut obligations) => {
759
- self . add_depth ( obligations. iter_mut ( ) , obligation. recursion_depth ) ;
760
-
751
+ Some ( obligations) => {
761
752
cache. wf_args . borrow_mut ( ) . push ( ( arg, previous_stack. depth ( ) ) ) ;
762
753
let result =
763
754
self . evaluate_predicates_recursively ( previous_stack, obligations) ;
@@ -826,10 +817,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
826
817
}
827
818
}
828
819
829
- self . add_depth (
830
- subobligations. iter_mut ( ) ,
831
- obligation. recursion_depth ,
832
- ) ;
820
+ // Need to explicitly set the depth of nested goals here as
821
+ // projection obligations can cycle by themselves and in
822
+ // `evaluate_predicates_recursively` we only add the depth
823
+ // for parent trait goals because only these get added to the
824
+ // `TraitObligationStackList`.
825
+ for subobligation in subobligations. iter_mut ( ) {
826
+ subobligation. set_depth_from_parent ( obligation. recursion_depth ) ;
827
+ }
833
828
let res = self . evaluate_predicates_recursively (
834
829
previous_stack,
835
830
subobligations,
@@ -909,38 +904,28 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
909
904
if a. def . did == b. def . did
910
905
&& tcx. def_kind ( a. def . did ) == DefKind :: AssocConst =>
911
906
{
912
- if let Ok ( new_obligations ) = self
907
+ if let Ok ( InferOk { obligations , value : ( ) } ) = self
913
908
. infcx
914
909
. at ( & obligation. cause , obligation. param_env )
915
910
. trace ( c1, c2)
916
911
. eq ( DefineOpaqueTypes :: No , a. substs , b. substs )
917
912
{
918
- let mut obligations = new_obligations. obligations ;
919
- self . add_depth (
920
- obligations. iter_mut ( ) ,
921
- obligation. recursion_depth ,
922
- ) ;
923
913
return self . evaluate_predicates_recursively (
924
914
previous_stack,
925
- obligations. into_iter ( ) ,
915
+ obligations,
926
916
) ;
927
917
}
928
918
}
929
919
( _, Unevaluated ( _) ) | ( Unevaluated ( _) , _) => ( ) ,
930
920
( _, _) => {
931
- if let Ok ( new_obligations ) = self
921
+ if let Ok ( InferOk { obligations , value : ( ) } ) = self
932
922
. infcx
933
923
. at ( & obligation. cause , obligation. param_env )
934
924
. eq ( DefineOpaqueTypes :: No , c1, c2)
935
925
{
936
- let mut obligations = new_obligations. obligations ;
937
- self . add_depth (
938
- obligations. iter_mut ( ) ,
939
- obligation. recursion_depth ,
940
- ) ;
941
926
return self . evaluate_predicates_recursively (
942
927
previous_stack,
943
- obligations. into_iter ( ) ,
928
+ obligations,
944
929
) ;
945
930
}
946
931
}
@@ -1366,24 +1351,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1366
1351
self . infcx . evaluation_cache . insert ( ( param_env, trait_pred) , dep_node, result) ;
1367
1352
}
1368
1353
1369
- /// For various reasons, it's possible for a subobligation
1370
- /// to have a *lower* recursion_depth than the obligation used to create it.
1371
- /// Projection sub-obligations may be returned from the projection cache,
1372
- /// which results in obligations with an 'old' `recursion_depth`.
1373
- /// Additionally, methods like `InferCtxt.subtype_predicate` produce
1374
- /// subobligations without taking in a 'parent' depth, causing the
1375
- /// generated subobligations to have a `recursion_depth` of `0`.
1376
- ///
1377
- /// To ensure that obligation_depth never decreases, we force all subobligations
1378
- /// to have at least the depth of the original obligation.
1379
- fn add_depth < T : ' cx , I : Iterator < Item = & ' cx mut Obligation < ' tcx , T > > > (
1380
- & self ,
1381
- it : I ,
1382
- min_depth : usize ,
1383
- ) {
1384
- it. for_each ( |o| o. recursion_depth = cmp:: max ( min_depth, o. recursion_depth ) + 1 ) ;
1385
- }
1386
-
1387
1354
fn check_recursion_depth < T > (
1388
1355
& self ,
1389
1356
depth : usize ,
0 commit comments