@@ -27,6 +27,7 @@ use super::generalize::{self, CombineDelegate, Generalization};
2727use super :: glb:: Glb ;
2828use super :: lub:: Lub ;
2929use super :: sub:: Sub ;
30+ use super :: StructurallyRelateAliases ;
3031use crate :: infer:: { DefineOpaqueTypes , InferCtxt , TypeTrace } ;
3132use crate :: traits:: { Obligation , PredicateObligations } ;
3233use rustc_middle:: infer:: canonical:: OriginalQueryValues ;
@@ -48,9 +49,10 @@ pub struct CombineFields<'infcx, 'tcx> {
4849}
4950
5051impl < ' tcx > InferCtxt < ' tcx > {
51- pub fn super_combine_tys < R > (
52+ pub ( super ) fn super_combine_tys < R > (
5253 & self ,
5354 relation : & mut R ,
55+ structurally_relate_aliases : StructurallyRelateAliases ,
5456 a : Ty < ' tcx > ,
5557 b : Ty < ' tcx > ,
5658 ) -> RelateResult < ' tcx , Ty < ' tcx > >
@@ -117,8 +119,15 @@ impl<'tcx> InferCtxt<'tcx> {
117119 }
118120
119121 ( _, ty:: Alias ( ..) ) | ( ty:: Alias ( ..) , _) if self . next_trait_solver ( ) => {
120- relation. register_type_relate_obligation ( a, b) ;
121- Ok ( a)
122+ match structurally_relate_aliases {
123+ StructurallyRelateAliases :: Yes => {
124+ ty:: relate:: structurally_relate_tys ( relation, a, b)
125+ }
126+ StructurallyRelateAliases :: No => {
127+ relation. register_type_relate_obligation ( a, b) ;
128+ Ok ( a)
129+ }
130+ }
122131 }
123132
124133 // All other cases of inference are errors
@@ -139,9 +148,10 @@ impl<'tcx> InferCtxt<'tcx> {
139148 }
140149 }
141150
142- pub fn super_combine_consts < R > (
151+ pub ( super ) fn super_combine_consts < R > (
143152 & self ,
144153 relation : & mut R ,
154+ structurally_relate_aliases : StructurallyRelateAliases ,
145155 a : ty:: Const < ' tcx > ,
146156 b : ty:: Const < ' tcx > ,
147157 ) -> RelateResult < ' tcx , ty:: Const < ' tcx > >
@@ -225,11 +235,21 @@ impl<'tcx> InferCtxt<'tcx> {
225235 }
226236
227237 ( ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) , _) => {
228- return self . unify_const_variable ( vid, b, relation. param_env ( ) ) ;
238+ return self . unify_const_variable (
239+ structurally_relate_aliases,
240+ relation. param_env ( ) ,
241+ vid,
242+ b,
243+ ) ;
229244 }
230245
231246 ( _, ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) ) => {
232- return self . unify_const_variable ( vid, a, relation. param_env ( ) ) ;
247+ return self . unify_const_variable (
248+ structurally_relate_aliases,
249+ relation. param_env ( ) ,
250+ vid,
251+ a,
252+ ) ;
233253 }
234254
235255 ( ty:: ConstKind :: Infer ( InferConst :: EffectVar ( vid) ) , _) => {
@@ -308,9 +328,10 @@ impl<'tcx> InferCtxt<'tcx> {
308328 #[ instrument( level = "debug" , skip( self ) ) ]
309329 fn unify_const_variable (
310330 & self ,
331+ structurally_relate_aliases : StructurallyRelateAliases ,
332+ param_env : ty:: ParamEnv < ' tcx > ,
311333 target_vid : ty:: ConstVid ,
312334 ct : ty:: Const < ' tcx > ,
313- param_env : ty:: ParamEnv < ' tcx > ,
314335 ) -> RelateResult < ' tcx , ty:: Const < ' tcx > > {
315336 let span = match self . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( target_vid) {
316337 ConstVariableValue :: Known { value } => {
@@ -323,6 +344,7 @@ impl<'tcx> InferCtxt<'tcx> {
323344 let Generalization { value_may_be_infer : value, needs_wf : _ } = generalize:: generalize (
324345 self ,
325346 & mut CombineDelegate { infcx : self , span } ,
347+ structurally_relate_aliases,
326348 ct,
327349 target_vid,
328350 ty:: Variance :: Invariant ,
@@ -335,7 +357,7 @@ impl<'tcx> InferCtxt<'tcx> {
335357 Ok ( value)
336358 }
337359
338- fn unify_integral_variable (
360+ pub ( super ) fn unify_integral_variable (
339361 & self ,
340362 vid_is_expected : bool ,
341363 vid : ty:: IntVid ,
@@ -352,7 +374,7 @@ impl<'tcx> InferCtxt<'tcx> {
352374 }
353375 }
354376
355- fn unify_float_variable (
377+ pub ( super ) fn unify_float_variable (
356378 & self ,
357379 vid_is_expected : bool ,
358380 vid : ty:: FloatVid ,
@@ -366,7 +388,7 @@ impl<'tcx> InferCtxt<'tcx> {
366388 Ok ( Ty :: new_float ( self . tcx , val) )
367389 }
368390
369- fn unify_effect_variable (
391+ pub ( super ) fn unify_effect_variable (
370392 & self ,
371393 vid_is_expected : bool ,
372394 vid : ty:: EffectVid ,
@@ -414,6 +436,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
414436 #[ instrument( skip( self ) , level = "debug" ) ]
415437 pub fn instantiate (
416438 & mut self ,
439+ structurally_relate_aliases : StructurallyRelateAliases ,
417440 a_ty : Ty < ' tcx > ,
418441 ambient_variance : ty:: Variance ,
419442 b_vid : ty:: TyVid ,
@@ -436,6 +459,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
436459 let Generalization { value_may_be_infer : b_ty, needs_wf } = generalize:: generalize (
437460 self . infcx ,
438461 & mut CombineDelegate { infcx : self . infcx , span : self . trace . span ( ) } ,
462+ structurally_relate_aliases,
439463 a_ty,
440464 b_vid,
441465 ambient_variance,
@@ -564,23 +588,23 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
564588 fn alias_relate_direction ( & self ) -> ty:: AliasRelationDirection ;
565589}
566590
567- fn int_unification_error < ' tcx > (
591+ pub ( super ) fn int_unification_error < ' tcx > (
568592 a_is_expected : bool ,
569593 v : ( ty:: IntVarValue , ty:: IntVarValue ) ,
570594) -> TypeError < ' tcx > {
571595 let ( a, b) = v;
572596 TypeError :: IntMismatch ( ExpectedFound :: new ( a_is_expected, a, b) )
573597}
574598
575- fn float_unification_error < ' tcx > (
599+ pub ( super ) fn float_unification_error < ' tcx > (
576600 a_is_expected : bool ,
577601 v : ( ty:: FloatVarValue , ty:: FloatVarValue ) ,
578602) -> TypeError < ' tcx > {
579603 let ( ty:: FloatVarValue ( a) , ty:: FloatVarValue ( b) ) = v;
580604 TypeError :: FloatMismatch ( ExpectedFound :: new ( a_is_expected, a, b) )
581605}
582606
583- fn effect_unification_error < ' tcx > (
607+ pub ( super ) fn effect_unification_error < ' tcx > (
584608 _tcx : TyCtxt < ' tcx > ,
585609 _a_is_expected : bool ,
586610 ( _a, _b) : ( EffectVarValue < ' tcx > , EffectVarValue < ' tcx > ) ,
0 commit comments