@@ -15,8 +15,8 @@ use rustc_middle::traits::solve::{
1515} ;
1616use rustc_middle:: traits:: DefiningAnchor ;
1717use rustc_middle:: ty:: {
18- self , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt ,
19- TypeVisitor ,
18+ self , OpaqueTypeKey , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable ,
19+ TypeVisitableExt , TypeVisitor ,
2020} ;
2121use rustc_span:: DUMMY_SP ;
2222use std:: ops:: ControlFlow ;
@@ -191,16 +191,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
191191 . with_opaque_type_inference ( canonical_input. value . anchor )
192192 . build_with_canonical ( DUMMY_SP , & canonical_input) ;
193193
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- }
204194 let mut ecx = EvalCtxt {
205195 infcx,
206196 var_values,
@@ -211,6 +201,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
211201 tainted : Ok ( ( ) ) ,
212202 } ;
213203
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+
214213 let result = ecx. compute_goal ( input. goal ) ;
215214
216215 // When creating a query response we clone the opaque type constraints
@@ -729,18 +728,42 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
729728 self . infcx . opaque_type_origin ( def_id) . is_some ( )
730729 }
731730
732- pub ( super ) fn register_opaque_ty (
731+ pub ( super ) fn insert_hidden_type (
733732 & mut self ,
734- a : ty:: OpaqueTypeKey < ' tcx > ,
735- b : Ty < ' tcx > ,
733+ opaque_type_key : OpaqueTypeKey < ' tcx > ,
736734 param_env : ty:: ParamEnv < ' tcx > ,
735+ hidden_ty : Ty < ' tcx > ,
737736 ) -> 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 ( ) ) ) ;
741747 Ok ( ( ) )
742748 }
743749
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+
744767 // Do something for each opaque/hidden pair defined with `def_id` in the
745768 // current inference context.
746769 pub ( super ) fn unify_existing_opaque_tys (
@@ -762,15 +785,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
762785 ecx. eq ( param_env, a, b) ?;
763786 }
764787 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) ;
774789 ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
775790 } ) ) ;
776791 }
0 commit comments