@@ -195,11 +195,13 @@ fn satisfied_from_param_env<'tcx>(
195
195
match pred. kind ( ) . skip_binder ( ) {
196
196
ty:: PredicateKind :: ConstEvaluatable ( uv) => {
197
197
if let Some ( b_ct) = AbstractConst :: new ( tcx, uv) ? {
198
+ let const_unify_ctxt = ConstUnifyCtxt :: new ( tcx, param_env) ;
199
+
198
200
// Try to unify with each subtree in the AbstractConst to allow for
199
201
// `N + 1` being const evaluatable even if theres only a `ConstEvaluatable`
200
202
// predicate for `(N + 1) * 2`
201
203
let result = walk_abstract_const ( tcx, b_ct, |b_ct| {
202
- match try_unify ( tcx , ct, b_ct, param_env ) {
204
+ match const_unify_ctxt . try_unify ( ct, b_ct) {
203
205
true => ControlFlow :: BREAK ,
204
206
false => ControlFlow :: CONTINUE ,
205
207
}
@@ -569,18 +571,6 @@ pub(super) fn thir_abstract_const<'tcx>(
569
571
}
570
572
}
571
573
572
- /// Tries to unify two abstract constants using structural equality.
573
- #[ instrument( skip( tcx) , level = "debug" ) ]
574
- pub ( super ) fn try_unify < ' tcx > (
575
- tcx : TyCtxt < ' tcx > ,
576
- a : AbstractConst < ' tcx > ,
577
- b : AbstractConst < ' tcx > ,
578
- param_env : ty:: ParamEnv < ' tcx > ,
579
- ) -> bool {
580
- let const_unify_ctxt = ConstUnifyCtxt :: new ( tcx, param_env) ;
581
- const_unify_ctxt. try_unify_inner ( a, b)
582
- }
583
-
584
574
pub ( super ) fn try_unify_abstract_consts < ' tcx > (
585
575
tcx : TyCtxt < ' tcx > ,
586
576
( a, b) : ( ty:: Unevaluated < ' tcx , ( ) > , ty:: Unevaluated < ' tcx , ( ) > ) ,
@@ -589,7 +579,8 @@ pub(super) fn try_unify_abstract_consts<'tcx>(
589
579
( || {
590
580
if let Some ( a) = AbstractConst :: new ( tcx, a) ? {
591
581
if let Some ( b) = AbstractConst :: new ( tcx, b) ? {
592
- return Ok ( try_unify ( tcx, a, b, param_env) ) ;
582
+ let const_unify_ctxt = ConstUnifyCtxt :: new ( tcx, param_env) ;
583
+ return Ok ( const_unify_ctxt. try_unify ( a, b) ) ;
593
584
}
594
585
}
595
586
@@ -666,7 +657,7 @@ impl<'tcx> ConstUnifyCtxt<'tcx> {
666
657
667
658
/// Tries to unify two abstract constants using structural equality.
668
659
#[ instrument( skip( self ) , level = "debug" ) ]
669
- fn try_unify_inner ( & self , a : AbstractConst < ' tcx > , b : AbstractConst < ' tcx > ) -> bool {
660
+ fn try_unify ( & self , a : AbstractConst < ' tcx > , b : AbstractConst < ' tcx > ) -> bool {
670
661
let a = if let Some ( a) = self . try_replace_substs_in_root ( a) {
671
662
a
672
663
} else {
@@ -723,23 +714,23 @@ impl<'tcx> ConstUnifyCtxt<'tcx> {
723
714
}
724
715
}
725
716
( Node :: Binop ( a_op, al, ar) , Node :: Binop ( b_op, bl, br) ) if a_op == b_op => {
726
- self . try_unify_inner ( a. subtree ( al) , b. subtree ( bl) )
727
- && self . try_unify_inner ( a. subtree ( ar) , b. subtree ( br) )
717
+ self . try_unify ( a. subtree ( al) , b. subtree ( bl) )
718
+ && self . try_unify ( a. subtree ( ar) , b. subtree ( br) )
728
719
}
729
720
( Node :: UnaryOp ( a_op, av) , Node :: UnaryOp ( b_op, bv) ) if a_op == b_op => {
730
- self . try_unify_inner ( a. subtree ( av) , b. subtree ( bv) )
721
+ self . try_unify ( a. subtree ( av) , b. subtree ( bv) )
731
722
}
732
723
( Node :: FunctionCall ( a_f, a_args) , Node :: FunctionCall ( b_f, b_args) )
733
724
if a_args. len ( ) == b_args. len ( ) =>
734
725
{
735
- self . try_unify_inner ( a. subtree ( a_f) , b. subtree ( b_f) )
726
+ self . try_unify ( a. subtree ( a_f) , b. subtree ( b_f) )
736
727
&& iter:: zip ( a_args, b_args)
737
- . all ( |( & an, & bn) | self . try_unify_inner ( a. subtree ( an) , b. subtree ( bn) ) )
728
+ . all ( |( & an, & bn) | self . try_unify ( a. subtree ( an) , b. subtree ( bn) ) )
738
729
}
739
730
( Node :: Cast ( a_kind, a_operand, a_ty) , Node :: Cast ( b_kind, b_operand, b_ty) )
740
731
if ( a_ty == b_ty) && ( a_kind == b_kind) =>
741
732
{
742
- self . try_unify_inner ( a. subtree ( a_operand) , b. subtree ( b_operand) )
733
+ self . try_unify ( a. subtree ( a_operand) , b. subtree ( b_operand) )
743
734
}
744
735
// use this over `_ => false` to make adding variants to `Node` less error prone
745
736
( Node :: Cast ( ..) , _)
0 commit comments