@@ -319,7 +319,7 @@ enum BuiltinImplConditions<'tcx> {
319319/// all the "potential success" candidates can potentially succeed,
320320/// so they are no-ops when unioned with a definite error, and within
321321/// the categories it's easy to see that the unions are correct.
322- enum EvaluationResult {
322+ pub enum EvaluationResult {
323323 /// Evaluation successful
324324 EvaluatedToOk ,
325325 /// Evaluation is known to be ambiguous - it *might* hold for some
@@ -385,7 +385,7 @@ enum EvaluationResult {
385385}
386386
387387impl EvaluationResult {
388- fn may_apply ( self ) -> bool {
388+ pub fn may_apply ( self ) -> bool {
389389 match self {
390390 EvaluatedToOk |
391391 EvaluatedToAmbig |
@@ -408,10 +408,18 @@ impl EvaluationResult {
408408 }
409409}
410410
411+ impl_stable_hash_for ! ( enum self :: EvaluationResult {
412+ EvaluatedToOk ,
413+ EvaluatedToAmbig ,
414+ EvaluatedToUnknown ,
415+ EvaluatedToRecur ,
416+ EvaluatedToErr
417+ } ) ;
418+
411419#[ derive( Clone , Debug , PartialEq , Eq ) ]
412420/// Indicates that trait evaluation caused overflow. Stores the obligation
413421/// that hit the recursion limit.
414- pub struct OverflowError < ' tcx > ( TraitObligation < ' tcx > ) ;
422+ pub struct OverflowError < ' tcx > ( pub TraitObligation < ' tcx > ) ;
415423
416424impl < ' tcx > From < OverflowError < ' tcx > > for SelectionError < ' tcx > {
417425 fn from ( OverflowError ( o) : OverflowError < ' tcx > ) -> SelectionError < ' tcx > {
@@ -574,9 +582,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
574582 debug ! ( "evaluate_obligation({:?})" ,
575583 obligation) ;
576584
577- match self . probe ( |this, _| {
578- this. evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
579- } ) {
585+ match self . evaluate_obligation_recursively ( obligation) {
580586 Ok ( result) => result. may_apply ( ) ,
581587 Err ( OverflowError ( o) ) => self . infcx ( ) . report_overflow_error ( & o, true )
582588 }
@@ -592,14 +598,23 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
592598 debug ! ( "evaluate_obligation_conservatively({:?})" ,
593599 obligation) ;
594600
595- match self . probe ( |this, _| {
596- this. evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
597- } ) {
601+ match self . evaluate_obligation_recursively ( obligation) {
598602 Ok ( result) => result == EvaluatedToOk ,
599603 Err ( OverflowError ( o) ) => self . infcx ( ) . report_overflow_error ( & o, true )
600604 }
601605 }
602606
607+ /// Evaluates whether the obligation `obligation` can be satisfied and returns
608+ /// an `EvaluationResult`.
609+ pub fn evaluate_obligation_recursively ( & mut self ,
610+ obligation : & PredicateObligation < ' tcx > )
611+ -> Result < EvaluationResult , OverflowError < ' tcx > >
612+ {
613+ self . probe ( |this, _| {
614+ this. evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
615+ } )
616+ }
617+
603618 /// Evaluates the predicates in `predicates` recursively. Note that
604619 /// this applies projections in the predicates, and therefore
605620 /// is run within an inference probe.
0 commit comments