@@ -8,6 +8,7 @@ use rustc_data_structures::unord::ExtendUnord;
8
8
use rustc_errors:: ErrorGuaranteed ;
9
9
use rustc_hir:: intravisit:: { self , InferKind , Visitor } ;
10
10
use rustc_hir:: { self as hir, AmbigArg , HirId } ;
11
+ use rustc_infer:: traits:: solve:: Goal ;
11
12
use rustc_middle:: span_bug;
12
13
use rustc_middle:: traits:: ObligationCause ;
13
14
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , PointerCoercion } ;
@@ -764,7 +765,32 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
764
765
T : TypeFoldable < TyCtxt < ' tcx > > ,
765
766
{
766
767
let value = self . fcx . resolve_vars_if_possible ( value) ;
767
- let value = value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body , true ) ) ;
768
+
769
+ let mut goals = vec ! [ ] ;
770
+ let value =
771
+ value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body , true , & mut goals) ) ;
772
+
773
+ // Ensure that we resolve goals we get from normalizing coroutine interiors,
774
+ // but we shouldn't expect those goals to need normalizing (or else we'd get
775
+ // into a somewhat awkward fixpoint situation, and we don't need it anyways).
776
+ let mut unexpected_goals = vec ! [ ] ;
777
+ self . typeck_results . coroutine_stalled_predicates . extend (
778
+ goals
779
+ . into_iter ( )
780
+ . map ( |pred| {
781
+ self . fcx . resolve_vars_if_possible ( pred) . fold_with ( & mut Resolver :: new (
782
+ self . fcx ,
783
+ span,
784
+ self . body ,
785
+ false ,
786
+ & mut unexpected_goals,
787
+ ) )
788
+ } )
789
+ // FIXME: throwing away the param-env :(
790
+ . map ( |goal| ( goal. predicate , self . fcx . misc ( span. to_span ( self . fcx . tcx ) ) ) ) ,
791
+ ) ;
792
+ assert_eq ! ( unexpected_goals, vec![ ] ) ;
793
+
768
794
assert ! ( !value. has_infer( ) ) ;
769
795
770
796
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
@@ -782,7 +808,12 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
782
808
T : TypeFoldable < TyCtxt < ' tcx > > ,
783
809
{
784
810
let value = self . fcx . resolve_vars_if_possible ( value) ;
785
- let value = value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body , false ) ) ;
811
+
812
+ let mut goals = vec ! [ ] ;
813
+ let value =
814
+ value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body , false , & mut goals) ) ;
815
+ assert_eq ! ( goals, vec![ ] ) ;
816
+
786
817
assert ! ( !value. has_infer( ) ) ;
787
818
788
819
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
@@ -819,6 +850,7 @@ struct Resolver<'cx, 'tcx> {
819
850
/// Whether we should normalize using the new solver, disabled
820
851
/// both when using the old solver and when resolving predicates.
821
852
should_normalize : bool ,
853
+ nested_goals : & ' cx mut Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
822
854
}
823
855
824
856
impl < ' cx , ' tcx > Resolver < ' cx , ' tcx > {
@@ -827,8 +859,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
827
859
span : & ' cx dyn Locatable ,
828
860
body : & ' tcx hir:: Body < ' tcx > ,
829
861
should_normalize : bool ,
862
+ nested_goals : & ' cx mut Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
830
863
) -> Resolver < ' cx , ' tcx > {
831
- Resolver { fcx, span, body, should_normalize }
864
+ Resolver { fcx, span, body, nested_goals , should_normalize }
832
865
}
833
866
834
867
fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) -> ErrorGuaranteed {
@@ -865,12 +898,18 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
865
898
let cause = ObligationCause :: misc ( self . span . to_span ( tcx) , body_id) ;
866
899
let at = self . fcx . at ( & cause, self . fcx . param_env ) ;
867
900
let universes = vec ! [ None ; outer_exclusive_binder( value) . as_usize( ) ] ;
868
- solve:: deeply_normalize_with_skipped_universes ( at, value, universes) . unwrap_or_else (
869
- |errors| {
901
+ match solve:: deeply_normalize_with_skipped_universes_and_ambiguous_goals (
902
+ at, value, universes,
903
+ ) {
904
+ Ok ( ( value, goals) ) => {
905
+ self . nested_goals . extend ( goals) ;
906
+ value
907
+ }
908
+ Err ( errors) => {
870
909
let guar = self . fcx . err_ctxt ( ) . report_fulfillment_errors ( errors) ;
871
910
new_err ( tcx, guar)
872
- } ,
873
- )
911
+ }
912
+ }
874
913
} else {
875
914
value
876
915
} ;
0 commit comments