@@ -12,14 +12,15 @@ use crate::infer::canonical::{
1212 Canonical , CanonicalVarValues , CanonicalizedQueryResponse , Certainty , OriginalQueryValues ,
1313 QueryOutlivesConstraint , QueryRegionConstraints , QueryResponse ,
1414} ;
15+ use crate :: infer:: nll_relate:: { NormalizationStrategy , TypeRelating , TypeRelatingDelegate } ;
1516use crate :: infer:: region_constraints:: { Constraint , RegionConstraintData } ;
16- use crate :: infer:: InferCtxtBuilder ;
17- use crate :: infer:: { InferCtxt , InferOk , InferResult } ;
17+ use crate :: infer:: { InferCtxt , InferCtxtBuilder , InferOk , InferResult , NLLRegionVariableOrigin } ;
1818use crate :: traits:: query:: { Fallible , NoSolution } ;
19- use crate :: traits:: TraitEngine ;
19+ use crate :: traits:: { DomainGoal , TraitEngine } ;
2020use crate :: traits:: { Obligation , ObligationCause , PredicateObligation } ;
2121use rustc:: arena:: ArenaAllocatable ;
2222use rustc:: ty:: fold:: TypeFoldable ;
23+ use rustc:: ty:: relate:: TypeRelation ;
2324use rustc:: ty:: subst:: { GenericArg , GenericArgKind } ;
2425use rustc:: ty:: { self , BoundVar , Ty , TyCtxt } ;
2526use rustc_data_structures:: captures:: Captures ;
@@ -304,13 +305,31 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
304305 }
305306
306307 ( GenericArgKind :: Type ( v1) , GenericArgKind :: Type ( v2) ) => {
307- let ok = self . at ( cause, param_env) . eq ( v1, v2) ?;
308- obligations. extend ( ok. into_obligations ( ) ) ;
308+ TypeRelating :: new (
309+ self ,
310+ QueryTypeRelatingDelegate {
311+ infcx : self ,
312+ param_env,
313+ cause,
314+ obligations : & mut obligations,
315+ } ,
316+ ty:: Variance :: Invariant ,
317+ )
318+ . relate ( & v1, & v2) ?;
309319 }
310320
311321 ( GenericArgKind :: Const ( v1) , GenericArgKind :: Const ( v2) ) => {
312- let ok = self . at ( cause, param_env) . eq ( v1, v2) ?;
313- obligations. extend ( ok. into_obligations ( ) ) ;
322+ TypeRelating :: new (
323+ self ,
324+ QueryTypeRelatingDelegate {
325+ infcx : self ,
326+ param_env,
327+ cause,
328+ obligations : & mut obligations,
329+ } ,
330+ ty:: Variance :: Invariant ,
331+ )
332+ . relate ( & v1, & v2) ?;
314333 }
315334
316335 _ => {
@@ -656,3 +675,55 @@ pub fn make_query_region_constraints<'tcx>(
656675
657676 QueryRegionConstraints { outlives, member_constraints : member_constraints. clone ( ) }
658677}
678+
679+ struct QueryTypeRelatingDelegate < ' a , ' tcx > {
680+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
681+ obligations : & ' a mut Vec < PredicateObligation < ' tcx > > ,
682+ param_env : ty:: ParamEnv < ' tcx > ,
683+ cause : & ' a ObligationCause < ' tcx > ,
684+ }
685+
686+ impl < ' tcx > TypeRelatingDelegate < ' tcx > for QueryTypeRelatingDelegate < ' _ , ' tcx > {
687+ fn create_next_universe ( & mut self ) -> ty:: UniverseIndex {
688+ self . infcx . create_next_universe ( )
689+ }
690+
691+ fn next_existential_region_var ( & mut self , from_forall : bool ) -> ty:: Region < ' tcx > {
692+ let origin = NLLRegionVariableOrigin :: Existential { from_forall } ;
693+ self . infcx . next_nll_region_var ( origin)
694+ }
695+
696+ fn next_placeholder_region ( & mut self , placeholder : ty:: PlaceholderRegion ) -> ty:: Region < ' tcx > {
697+ self . infcx . tcx . mk_region ( ty:: RePlaceholder ( placeholder) )
698+ }
699+
700+ fn generalize_existential ( & mut self , universe : ty:: UniverseIndex ) -> ty:: Region < ' tcx > {
701+ self . infcx . next_nll_region_var_in_universe (
702+ NLLRegionVariableOrigin :: Existential { from_forall : false } ,
703+ universe,
704+ )
705+ }
706+
707+ fn push_outlives ( & mut self , sup : ty:: Region < ' tcx > , sub : ty:: Region < ' tcx > ) {
708+ self . obligations . push ( Obligation {
709+ cause : self . cause . clone ( ) ,
710+ param_env : self . param_env ,
711+ predicate : ty:: Predicate :: RegionOutlives ( ty:: Binder :: dummy ( ty:: OutlivesPredicate (
712+ sup, sub,
713+ ) ) ) ,
714+ recursion_depth : 0 ,
715+ } ) ;
716+ }
717+
718+ fn push_domain_goal ( & mut self , _: DomainGoal < ' tcx > ) {
719+ bug ! ( "should never be invoked with eager normalization" )
720+ }
721+
722+ fn normalization ( ) -> NormalizationStrategy {
723+ NormalizationStrategy :: Eager
724+ }
725+
726+ fn forbid_inference_vars ( ) -> bool {
727+ true
728+ }
729+ }
0 commit comments