@@ -12,14 +12,15 @@ use crate::infer::canonical::{
12
12
Canonical , CanonicalVarValues , CanonicalizedQueryResponse , Certainty , OriginalQueryValues ,
13
13
QueryOutlivesConstraint , QueryRegionConstraints , QueryResponse ,
14
14
} ;
15
+ use crate :: infer:: nll_relate:: { NormalizationStrategy , TypeRelating , TypeRelatingDelegate } ;
15
16
use 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 } ;
18
18
use crate :: traits:: query:: { Fallible , NoSolution } ;
19
- use crate :: traits:: TraitEngine ;
19
+ use crate :: traits:: { DomainGoal , TraitEngine } ;
20
20
use crate :: traits:: { Obligation , ObligationCause , PredicateObligation } ;
21
21
use rustc:: arena:: ArenaAllocatable ;
22
22
use rustc:: ty:: fold:: TypeFoldable ;
23
+ use rustc:: ty:: relate:: TypeRelation ;
23
24
use rustc:: ty:: subst:: { GenericArg , GenericArgKind } ;
24
25
use rustc:: ty:: { self , BoundVar , Ty , TyCtxt } ;
25
26
use rustc_data_structures:: captures:: Captures ;
@@ -304,13 +305,31 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
304
305
}
305
306
306
307
( 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) ?;
309
319
}
310
320
311
321
( 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) ?;
314
333
}
315
334
316
335
_ => {
@@ -656,3 +675,55 @@ pub fn make_query_region_constraints<'tcx>(
656
675
657
676
QueryRegionConstraints { outlives, member_constraints : member_constraints. clone ( ) }
658
677
}
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