@@ -23,11 +23,12 @@ use super::{Certainty, InferCtxtEvalExt};
2323/// here as this will have to deal with far more root goals than `evaluate_all`.
2424pub struct FulfillmentCtxt < ' tcx > {
2525 obligations : Vec < PredicateObligation < ' tcx > > ,
26+ defining_use_anchor : DefiningAnchor ,
2627}
2728
2829impl < ' tcx > FulfillmentCtxt < ' tcx > {
29- pub fn new ( ) -> FulfillmentCtxt < ' tcx > {
30- FulfillmentCtxt { obligations : Vec :: new ( ) }
30+ pub fn new ( defining_use_anchor : impl Into < DefiningAnchor > ) -> FulfillmentCtxt < ' tcx > {
31+ FulfillmentCtxt { obligations : Vec :: new ( ) , defining_use_anchor : defining_use_anchor . into ( ) }
3132 }
3233}
3334
@@ -51,11 +52,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
5152 . collect ( )
5253 }
5354
54- fn select_where_possible (
55- & mut self ,
56- infcx : & InferCtxt < ' tcx > ,
57- defining_use_anchor : DefiningAnchor ,
58- ) -> Vec < FulfillmentError < ' tcx > > {
55+ fn select_where_possible ( & mut self , infcx : & InferCtxt < ' tcx > ) -> Vec < FulfillmentError < ' tcx > > {
5956 let mut errors = Vec :: new ( ) ;
6057 for i in 0 .. {
6158 if !infcx. tcx . recursion_limit ( ) . value_within_limit ( i) {
@@ -65,71 +62,71 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
6562 let mut has_changed = false ;
6663 for obligation in mem:: take ( & mut self . obligations ) {
6764 let goal = obligation. clone ( ) . into ( ) ;
68- let ( changed, certainty) = match infcx . evaluate_root_goal ( goal , defining_use_anchor )
69- {
70- Ok ( result) => result,
71- Err ( NoSolution ) => {
72- errors. push ( FulfillmentError {
73- obligation : obligation. clone ( ) ,
74- code : match goal. predicate . kind ( ) . skip_binder ( ) {
75- ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( _) ) => {
76- FulfillmentErrorCode :: CodeProjectionError (
77- // FIXME: This could be a `Sorts` if the term is a type
78- MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
79- )
80- }
81- ty:: PredicateKind :: AliasEq ( _, _) => {
82- FulfillmentErrorCode :: CodeProjectionError (
83- MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
84- )
85- }
86- ty:: PredicateKind :: Subtype ( pred) => {
87- let ( a, b) = infcx. instantiate_binder_with_placeholders (
88- goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
89- ) ;
90- let expected_found = ExpectedFound :: new ( true , a, b) ;
91- FulfillmentErrorCode :: CodeSubtypeError (
92- expected_found,
93- TypeError :: Sorts ( expected_found) ,
94- )
95- }
96- ty:: PredicateKind :: Coerce ( pred) => {
97- let ( a, b) = infcx. instantiate_binder_with_placeholders (
98- goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
99- ) ;
100- let expected_found = ExpectedFound :: new ( false , a, b) ;
101- FulfillmentErrorCode :: CodeSubtypeError (
102- expected_found,
103- TypeError :: Sorts ( expected_found) ,
104- )
105- }
106- ty:: PredicateKind :: ConstEquate ( a, b) => {
107- let ( a, b) = infcx. instantiate_binder_with_placeholders (
108- goal. predicate . kind ( ) . rebind ( ( a, b) ) ,
109- ) ;
110- let expected_found = ExpectedFound :: new ( true , a, b) ;
111- FulfillmentErrorCode :: CodeConstEquateError (
112- expected_found,
113- TypeError :: ConstMismatch ( expected_found) ,
114- )
115- }
116- ty:: PredicateKind :: Clause ( _)
117- | ty:: PredicateKind :: WellFormed ( _)
118- | ty:: PredicateKind :: ObjectSafe ( _)
119- | ty:: PredicateKind :: ClosureKind ( _, _, _)
120- | ty:: PredicateKind :: ConstEvaluatable ( _)
121- | ty:: PredicateKind :: TypeWellFormedFromEnv ( _)
122- | ty:: PredicateKind :: Ambiguous => {
123- FulfillmentErrorCode :: CodeSelectionError (
124- SelectionError :: Unimplemented ,
125- )
126- }
127- } ,
128- root_obligation : obligation,
129- } ) ;
130- continue ;
131- }
132- } ;
65+ let ( changed, certainty) =
66+ match infcx . evaluate_root_goal ( goal , self . defining_use_anchor ) {
67+ Ok ( result) => result,
68+ Err ( NoSolution ) => {
69+ errors. push ( FulfillmentError {
70+ obligation : obligation. clone ( ) ,
71+ code : match goal. predicate . kind ( ) . skip_binder ( ) {
72+ ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( _) ) => {
73+ FulfillmentErrorCode :: CodeProjectionError (
74+ // FIXME: This could be a `Sorts` if the term is a type
75+ MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
76+ )
77+ }
78+ ty:: PredicateKind :: AliasEq ( _, _) => {
79+ FulfillmentErrorCode :: CodeProjectionError (
80+ MismatchedProjectionTypes { err : TypeError :: Mismatch } ,
81+ )
82+ }
83+ ty:: PredicateKind :: Subtype ( pred) => {
84+ let ( a, b) = infcx. instantiate_binder_with_placeholders (
85+ goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
86+ ) ;
87+ let expected_found = ExpectedFound :: new ( true , a, b) ;
88+ FulfillmentErrorCode :: CodeSubtypeError (
89+ expected_found,
90+ TypeError :: Sorts ( expected_found) ,
91+ )
92+ }
93+ ty:: PredicateKind :: Coerce ( pred) => {
94+ let ( a, b) = infcx. instantiate_binder_with_placeholders (
95+ goal. predicate . kind ( ) . rebind ( ( pred. a , pred. b ) ) ,
96+ ) ;
97+ let expected_found = ExpectedFound :: new ( false , a, b) ;
98+ FulfillmentErrorCode :: CodeSubtypeError (
99+ expected_found,
100+ TypeError :: Sorts ( expected_found) ,
101+ )
102+ }
103+ ty:: PredicateKind :: ConstEquate ( a, b) => {
104+ let ( a, b) = infcx. instantiate_binder_with_placeholders (
105+ goal. predicate . kind ( ) . rebind ( ( a, b) ) ,
106+ ) ;
107+ let expected_found = ExpectedFound :: new ( true , a, b) ;
108+ FulfillmentErrorCode :: CodeConstEquateError (
109+ expected_found,
110+ TypeError :: ConstMismatch ( expected_found) ,
111+ )
112+ }
113+ ty:: PredicateKind :: Clause ( _)
114+ | ty:: PredicateKind :: WellFormed ( _)
115+ | ty:: PredicateKind :: ObjectSafe ( _)
116+ | ty:: PredicateKind :: ClosureKind ( _, _, _)
117+ | ty:: PredicateKind :: ConstEvaluatable ( _)
118+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( _)
119+ | ty:: PredicateKind :: Ambiguous => {
120+ FulfillmentErrorCode :: CodeSelectionError (
121+ SelectionError :: Unimplemented ,
122+ )
123+ }
124+ } ,
125+ root_obligation : obligation,
126+ } ) ;
127+ continue ;
128+ }
129+ } ;
133130
134131 has_changed |= changed;
135132 match certainty {
@@ -156,4 +153,8 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
156153 ) -> Vec < PredicateObligation < ' tcx > > {
157154 unimplemented ! ( )
158155 }
156+
157+ fn defining_use_anchor ( & self ) -> DefiningAnchor {
158+ self . defining_use_anchor
159+ }
159160}
0 commit comments