@@ -662,32 +662,59 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
662662 tcx. features( ) . generic_const_exprs,
663663 "`ConstEquate` without a feature gate: {c1:?} {c2:?}" ,
664664 ) ;
665- debug ! ( ?c1, ?c2, "evaluate_predicate_recursively: equating consts" ) ;
666665
667- // FIXME: we probably should only try to unify abstract constants
668- // if the constants depend on generic parameters.
669- //
670- // Let's just see where this breaks :shrug:
671- if let ( ty:: ConstKind :: Unevaluated ( _) , ty:: ConstKind :: Unevaluated ( _) ) =
672- ( c1. kind ( ) , c2. kind ( ) )
673666 {
674- if let Ok ( Some ( a) ) = tcx. expand_abstract_consts ( c1)
675- && let Ok ( Some ( b) ) = tcx. expand_abstract_consts ( c2)
676- && a. ty ( ) == b. ty ( )
677- && let Ok ( new_obligations) = self
678- . infcx
679- . at ( & obligation. cause , obligation. param_env )
680- . eq ( a, b)
681- {
682- let mut obligations = new_obligations. obligations ;
683- self . add_depth (
684- obligations. iter_mut ( ) ,
685- obligation. recursion_depth ,
686- ) ;
687- return self . evaluate_predicates_recursively (
688- previous_stack,
689- obligations. into_iter ( ) ,
690- ) ;
667+ let c1 =
668+ if let Ok ( Some ( a) ) = tcx. expand_abstract_consts ( c1) { a } else { c1 } ;
669+ let c2 =
670+ if let Ok ( Some ( b) ) = tcx. expand_abstract_consts ( c2) { b } else { c2 } ;
671+ debug ! (
672+ "evalaute_predicate_recursively: equating consts:\n c1= {:?}\n c2= {:?}" ,
673+ c1, c2
674+ ) ;
675+
676+ use rustc_hir:: def:: DefKind ;
677+ use ty:: ConstKind :: Unevaluated ;
678+ match ( c1. kind ( ) , c2. kind ( ) ) {
679+ ( Unevaluated ( a) , Unevaluated ( b) )
680+ if a. def . did == b. def . did
681+ && tcx. def_kind ( a. def . did ) == DefKind :: AssocConst =>
682+ {
683+ if let Ok ( new_obligations) = self
684+ . infcx
685+ . at ( & obligation. cause , obligation. param_env )
686+ . trace ( c1, c2)
687+ . eq ( a. substs , b. substs )
688+ {
689+ let mut obligations = new_obligations. obligations ;
690+ self . add_depth (
691+ obligations. iter_mut ( ) ,
692+ obligation. recursion_depth ,
693+ ) ;
694+ return self . evaluate_predicates_recursively (
695+ previous_stack,
696+ obligations. into_iter ( ) ,
697+ ) ;
698+ }
699+ }
700+ ( _, Unevaluated ( _) ) | ( Unevaluated ( _) , _) => ( ) ,
701+ ( _, _) => {
702+ if let Ok ( new_obligations) = self
703+ . infcx
704+ . at ( & obligation. cause , obligation. param_env )
705+ . eq ( c1, c2)
706+ {
707+ let mut obligations = new_obligations. obligations ;
708+ self . add_depth (
709+ obligations. iter_mut ( ) ,
710+ obligation. recursion_depth ,
711+ ) ;
712+ return self . evaluate_predicates_recursively (
713+ previous_stack,
714+ obligations. into_iter ( ) ,
715+ ) ;
716+ }
717+ }
691718 }
692719 }
693720
0 commit comments