@@ -24,7 +24,8 @@ use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
2424use rustc_infer:: traits:: query:: NoSolution ;
2525use rustc_infer:: traits:: Obligation ;
2626use rustc_middle:: infer:: canonical:: Certainty as OldCertainty ;
27- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
27+ use rustc_middle:: traits:: solve:: { ExternalConstraints , ExternalConstraintsData } ;
28+ use rustc_middle:: ty:: { self , TyCtxt } ;
2829use rustc_middle:: ty:: {
2930 CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , ToPredicate , TypeOutlivesPredicate ,
3031} ;
@@ -72,8 +73,7 @@ impl<'tcx, P> From<Obligation<'tcx, P>> for Goal<'tcx, P> {
7273 Goal { param_env : obligation. param_env , predicate : obligation. predicate }
7374 }
7475}
75-
76- #[ derive( Debug , PartialEq , Eq , Clone , Hash , TypeFoldable , TypeVisitable ) ]
76+ #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , TypeFoldable , TypeVisitable ) ]
7777pub struct Response < ' tcx > {
7878 pub var_values : CanonicalVarValues < ' tcx > ,
7979 /// Additional constraints returned by this query.
@@ -121,14 +121,6 @@ pub enum MaybeCause {
121121 Overflow ,
122122}
123123
124- /// Additional constraints returned on success.
125- #[ derive( Debug , PartialEq , Eq , Clone , Hash , TypeFoldable , TypeVisitable , Default ) ]
126- pub struct ExternalConstraints < ' tcx > {
127- // FIXME: implement this.
128- regions : ( ) ,
129- opaque_types : Vec < ( Ty < ' tcx > , Ty < ' tcx > ) > ,
130- }
131-
132124type CanonicalGoal < ' tcx , T = ty:: Predicate < ' tcx > > = Canonical < ' tcx , Goal < ' tcx , T > > ;
133125type CanonicalResponse < ' tcx > = Canonical < ' tcx , Response < ' tcx > > ;
134126/// The result of evaluating a canonical query.
@@ -218,15 +210,14 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
218210 EvalCtxt { infcx, var_values, search_graph, in_projection_eq_hack : false } ;
219211 let result = ecx. compute_goal ( goal) ;
220212
221- // FIXME: `Response` should be `Copy`
222- if search_graph. try_finalize_goal ( tcx, canonical_goal, result. clone ( ) ) {
213+ if search_graph. try_finalize_goal ( tcx, canonical_goal, result) {
223214 return result;
224215 }
225216 }
226217 }
227218
228219 fn make_canonical_response ( & self , certainty : Certainty ) -> QueryResult < ' tcx > {
229- let external_constraints = take_external_constraints ( self . infcx ) ?;
220+ let external_constraints = compute_external_query_constraints ( self . infcx ) ?;
230221
231222 Ok ( self . infcx . canonicalize_response ( Response {
232223 var_values : self . var_values ,
@@ -461,18 +452,18 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
461452}
462453
463454#[ instrument( level = "debug" , skip( infcx) , ret) ]
464- fn take_external_constraints < ' tcx > (
455+ fn compute_external_query_constraints < ' tcx > (
465456 infcx : & InferCtxt < ' tcx > ,
466457) -> Result < ExternalConstraints < ' tcx > , NoSolution > {
467458 let region_obligations = infcx. take_registered_region_obligations ( ) ;
468459 let opaque_types = infcx. take_opaque_types_for_query_response ( ) ;
469- Ok ( ExternalConstraints {
460+ Ok ( infcx . tcx . intern_external_constraints ( ExternalConstraintsData {
470461 // FIXME: Now that's definitely wrong :)
471462 //
472463 // Should also do the leak check here I think
473464 regions : drop ( region_obligations) ,
474465 opaque_types,
475- } )
466+ } ) )
476467}
477468
478469fn instantiate_canonical_query_response < ' tcx > (
@@ -492,7 +483,10 @@ fn instantiate_canonical_query_response<'tcx>(
492483 Certainty :: Yes => OldCertainty :: Proven ,
493484 Certainty :: Maybe ( _) => OldCertainty :: Ambiguous ,
494485 } ,
495- opaque_types : resp. external_constraints . opaque_types ,
486+ // FIXME: This to_owned makes me sad, but we should eventually impl
487+ // `instantiate_query_response_and_region_obligations` separately
488+ // instead of piggybacking off of the old implementation.
489+ opaque_types : resp. external_constraints . opaque_types . to_owned ( ) ,
496490 value : resp. certainty ,
497491 } ) ,
498492 ) else { bug ! ( ) ; } ;
@@ -510,7 +504,10 @@ pub(super) fn response_no_constraints<'tcx>(
510504 variables : goal. variables ,
511505 value : Response {
512506 var_values : CanonicalVarValues :: make_identity ( tcx, goal. variables ) ,
513- external_constraints : Default :: default ( ) ,
507+ // FIXME: maybe we should store the "no response" version in tcx, like
508+ // we do for tcx.types and stuff.
509+ external_constraints : tcx
510+ . intern_external_constraints ( ExternalConstraintsData :: default ( ) ) ,
514511 certainty,
515512 } ,
516513 } )
0 commit comments