@@ -687,14 +687,23 @@ pub struct CombinedSnapshot<'a, 'tcx> {
687
687
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
688
688
/// calls `tcx.try_unify_abstract_consts` after
689
689
/// canonicalizing the consts.
690
+ #[ instrument( skip( self ) , level = "debug" ) ]
690
691
pub fn try_unify_abstract_consts (
691
692
& self ,
692
693
a : ty:: Unevaluated < ' tcx , ( ) > ,
693
694
b : ty:: Unevaluated < ' tcx , ( ) > ,
694
695
param_env : ty:: ParamEnv < ' tcx > ,
695
696
) -> bool {
697
+ // Reject any attempt to unify two unevaluated constants that contain inference
698
+ // variables.
699
+ // FIXME `TyCtxt::const_eval_resolve` already rejects the resolution of those
700
+ // constants early, but the canonicalization below messes with that mechanism.
701
+ if a. substs . has_infer_types_or_consts ( ) || b. substs . has_infer_types_or_consts ( ) {
702
+ debug ! ( "a or b contain infer vars in its substs -> cannot unify" ) ;
703
+ return false ;
704
+ }
705
+
696
706
let canonical = self . canonicalize_query ( ( a, b) , & mut OriginalQueryValues :: default ( ) ) ;
697
- debug ! ( "canonical consts: {:?}" , & canonical. value) ;
698
707
699
708
self . tcx . try_unify_abstract_consts ( param_env. and ( canonical. value ) )
700
709
}
@@ -1599,22 +1608,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1599
1608
///
1600
1609
/// This handles inferences variables within both `param_env` and `substs` by
1601
1610
/// performing the operation on their respective canonical forms.
1611
+ #[ instrument( skip( self ) , level = "debug" ) ]
1602
1612
pub fn const_eval_resolve (
1603
1613
& self ,
1604
1614
param_env : ty:: ParamEnv < ' tcx > ,
1605
1615
unevaluated : ty:: Unevaluated < ' tcx > ,
1606
1616
span : Option < Span > ,
1607
1617
) -> EvalToConstValueResult < ' tcx > {
1608
1618
let substs = self . resolve_vars_if_possible ( unevaluated. substs ) ;
1619
+ debug ! ( ?substs) ;
1609
1620
1610
1621
// Postpone the evaluation of constants whose substs depend on inference
1611
1622
// variables
1612
1623
if substs. has_infer_types_or_consts ( ) {
1624
+ debug ! ( "has infer types or consts" ) ;
1613
1625
return Err ( ErrorHandled :: TooGeneric ) ;
1614
1626
}
1615
1627
1616
1628
let param_env_erased = self . tcx . erase_regions ( param_env) ;
1617
1629
let substs_erased = self . tcx . erase_regions ( substs) ;
1630
+ debug ! ( ?param_env_erased) ;
1631
+ debug ! ( ?substs_erased) ;
1618
1632
1619
1633
let unevaluated = ty:: Unevaluated {
1620
1634
def : unevaluated. def ,
0 commit comments