@@ -38,12 +38,13 @@ pub struct InspectGoal<'a, 'tcx> {
3838 orig_values : Vec < ty:: GenericArg < ' tcx > > ,
3939 goal : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
4040 evaluation : inspect:: CanonicalGoalEvaluation < ' tcx > ,
41+ source : GoalSource ,
4142}
4243
4344pub struct InspectCandidate < ' a , ' tcx > {
4445 goal : & ' a InspectGoal < ' a , ' tcx > ,
4546 kind : inspect:: ProbeKind < ' tcx > ,
46- nested_goals : Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
47+ nested_goals : Vec < ( GoalSource , inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
4748 final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
4849 result : QueryResult < ' tcx > ,
4950 shallow_certainty : Certainty ,
@@ -96,13 +97,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
9697 let instantiated_goals: Vec < _ > = self
9798 . nested_goals
9899 . iter ( )
99- . map ( |goal| {
100- canonical:: instantiate_canonical_state (
101- infcx,
102- span,
103- param_env,
104- & mut orig_values,
105- * goal,
100+ . map ( |( source, goal) | {
101+ (
102+ * source,
103+ canonical:: instantiate_canonical_state (
104+ infcx,
105+ span,
106+ param_env,
107+ & mut orig_values,
108+ * goal,
109+ ) ,
106110 )
107111 } )
108112 . collect ( ) ;
@@ -117,7 +121,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
117121
118122 instantiated_goals
119123 . into_iter ( )
120- . map ( |goal| {
124+ . map ( |( source , goal) | {
121125 let proof_tree = match goal. predicate . kind ( ) . no_bound_vars ( ) {
122126 Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
123127 let unconstrained_term = match term. unpack ( ) {
@@ -150,7 +154,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
150154 }
151155 _ => infcx. evaluate_root_goal ( goal, GenerateProofTree :: Yes ) . 1 ,
152156 } ;
153- InspectGoal :: new ( infcx, self . goal . depth + 1 , proof_tree. unwrap ( ) )
157+ InspectGoal :: new ( infcx, self . goal . depth + 1 , proof_tree. unwrap ( ) , source )
154158 } )
155159 . collect ( )
156160 }
@@ -175,16 +179,23 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
175179 self . evaluation . result . map ( |c| c. value . certainty )
176180 }
177181
182+ pub fn source ( & self ) -> GoalSource {
183+ self . source
184+ }
185+
178186 fn candidates_recur (
179187 & ' a self ,
180188 candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
181- nested_goals : & mut Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
189+ nested_goals : & mut Vec < (
190+ GoalSource ,
191+ inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
192+ ) > ,
182193 probe : & inspect:: Probe < ' tcx > ,
183194 ) {
184195 let mut shallow_certainty = None ;
185196 for step in & probe. steps {
186197 match step {
187- & inspect:: ProbeStep :: AddGoal ( _source , goal) => nested_goals. push ( goal) ,
198+ & inspect:: ProbeStep :: AddGoal ( source , goal) => nested_goals. push ( ( source , goal) ) ,
188199 inspect:: ProbeStep :: NestedProbe ( ref probe) => {
189200 // Nested probes have to prove goals added in their parent
190201 // but do not leak them, so we truncate the added goals
@@ -262,7 +273,12 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
262273 candidates. pop ( ) . filter ( |_| candidates. is_empty ( ) )
263274 }
264275
265- fn new ( infcx : & ' a InferCtxt < ' tcx > , depth : usize , root : inspect:: GoalEvaluation < ' tcx > ) -> Self {
276+ fn new (
277+ infcx : & ' a InferCtxt < ' tcx > ,
278+ depth : usize ,
279+ root : inspect:: GoalEvaluation < ' tcx > ,
280+ source : GoalSource ,
281+ ) -> Self {
266282 let inspect:: GoalEvaluation { uncanonicalized_goal, kind, evaluation } = root;
267283 match kind {
268284 inspect:: GoalEvaluationKind :: Root { orig_values } => InspectGoal {
@@ -271,6 +287,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
271287 orig_values,
272288 goal : uncanonicalized_goal. fold_with ( & mut EagerResolver :: new ( infcx) ) ,
273289 evaluation,
290+ source,
274291 } ,
275292 inspect:: GoalEvaluationKind :: Nested { .. } => unreachable ! ( ) ,
276293 }
@@ -299,6 +316,6 @@ impl<'tcx> InferCtxt<'tcx> {
299316 ) -> V :: Result {
300317 let ( _, proof_tree) = self . evaluate_root_goal ( goal, GenerateProofTree :: Yes ) ;
301318 let proof_tree = proof_tree. unwrap ( ) ;
302- visitor. visit_goal ( & InspectGoal :: new ( self , 0 , proof_tree) )
319+ visitor. visit_goal ( & InspectGoal :: new ( self , 0 , proof_tree, GoalSource :: Misc ) )
303320 }
304321}
0 commit comments