@@ -15,8 +15,8 @@ use rustc_middle::traits::solve::{
15
15
} ;
16
16
use rustc_middle:: traits:: DefiningAnchor ;
17
17
use rustc_middle:: ty:: {
18
- self , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt ,
19
- TypeVisitor ,
18
+ self , OpaqueTypeKey , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable ,
19
+ TypeVisitableExt , TypeVisitor ,
20
20
} ;
21
21
use rustc_span:: DUMMY_SP ;
22
22
use std:: ops:: ControlFlow ;
@@ -191,16 +191,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
191
191
. with_opaque_type_inference ( canonical_input. value . anchor )
192
192
. build_with_canonical ( DUMMY_SP , & canonical_input) ;
193
193
194
- for & ( a, b) in & input. predefined_opaques_in_body . opaque_types {
195
- let InferOk { value : ( ) , obligations } = infcx
196
- . register_hidden_type_in_new_solver ( a, input. goal . param_env , b)
197
- . expect ( "expected opaque type instantiation to succeed" ) ;
198
- // We're only registering opaques already defined by the caller,
199
- // so we're not responsible for proving that they satisfy their
200
- // item bounds, unless we use them in a normalizes-to goal,
201
- // which is handled in `EvalCtxt::unify_existing_opaque_tys`.
202
- let _ = obligations;
203
- }
204
194
let mut ecx = EvalCtxt {
205
195
infcx,
206
196
var_values,
@@ -211,6 +201,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
211
201
tainted : Ok ( ( ) ) ,
212
202
} ;
213
203
204
+ for & ( key, ty) in & input. predefined_opaques_in_body . opaque_types {
205
+ ecx. insert_hidden_type ( key, input. goal . param_env , ty)
206
+ . expect ( "failed to prepopulate opaque types" ) ;
207
+ }
208
+
209
+ if !ecx. nested_goals . is_empty ( ) {
210
+ panic ! ( "prepopulating opaque types shouldn't add goals: {:?}" , ecx. nested_goals) ;
211
+ }
212
+
214
213
let result = ecx. compute_goal ( input. goal ) ;
215
214
216
215
// When creating a query response we clone the opaque type constraints
@@ -729,18 +728,42 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
729
728
self . infcx . opaque_type_origin ( def_id) . is_some ( )
730
729
}
731
730
732
- pub ( super ) fn register_opaque_ty (
731
+ pub ( super ) fn insert_hidden_type (
733
732
& mut self ,
734
- a : ty:: OpaqueTypeKey < ' tcx > ,
735
- b : Ty < ' tcx > ,
733
+ opaque_type_key : OpaqueTypeKey < ' tcx > ,
736
734
param_env : ty:: ParamEnv < ' tcx > ,
735
+ hidden_ty : Ty < ' tcx > ,
737
736
) -> Result < ( ) , NoSolution > {
738
- let InferOk { value : ( ) , obligations } =
739
- self . infcx . register_hidden_type_in_new_solver ( a, param_env, b) ?;
740
- self . add_goals ( obligations. into_iter ( ) . map ( |obligation| obligation. into ( ) ) ) ;
737
+ let mut obligations = Vec :: new ( ) ;
738
+ self . infcx . insert_hidden_type (
739
+ opaque_type_key,
740
+ & ObligationCause :: dummy ( ) ,
741
+ param_env,
742
+ hidden_ty,
743
+ true ,
744
+ & mut obligations,
745
+ ) ?;
746
+ self . add_goals ( obligations. into_iter ( ) . map ( |o| o. into ( ) ) ) ;
741
747
Ok ( ( ) )
742
748
}
743
749
750
+ pub ( super ) fn add_item_bounds_for_hidden_type (
751
+ & mut self ,
752
+ opaque_type_key : OpaqueTypeKey < ' tcx > ,
753
+ param_env : ty:: ParamEnv < ' tcx > ,
754
+ hidden_ty : Ty < ' tcx > ,
755
+ ) {
756
+ let mut obligations = Vec :: new ( ) ;
757
+ self . infcx . add_item_bounds_for_hidden_type (
758
+ opaque_type_key,
759
+ ObligationCause :: dummy ( ) ,
760
+ param_env,
761
+ hidden_ty,
762
+ & mut obligations,
763
+ ) ;
764
+ self . add_goals ( obligations. into_iter ( ) . map ( |o| o. into ( ) ) ) ;
765
+ }
766
+
744
767
// Do something for each opaque/hidden pair defined with `def_id` in the
745
768
// current inference context.
746
769
pub ( super ) fn unify_existing_opaque_tys (
@@ -762,15 +785,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
762
785
ecx. eq ( param_env, a, b) ?;
763
786
}
764
787
ecx. eq ( param_env, candidate_ty, ty) ?;
765
- let mut obl = vec ! [ ] ;
766
- ecx. infcx . add_item_bounds_for_hidden_type (
767
- candidate_key,
768
- ObligationCause :: dummy ( ) ,
769
- param_env,
770
- candidate_ty,
771
- & mut obl,
772
- ) ;
773
- ecx. add_goals ( obl. into_iter ( ) . map ( Into :: into) ) ;
788
+ ecx. add_item_bounds_for_hidden_type ( candidate_key, param_env, candidate_ty) ;
774
789
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
775
790
} ) ) ;
776
791
}
0 commit comments