Skip to content

Commit ded5d6a

Browse files
Store goal source in InspectGoal
1 parent 1b3a329 commit ded5d6a

File tree

1 file changed

+19
-8
lines changed
  • compiler/rustc_trait_selection/src/solve/inspect

1 file changed

+19
-8
lines changed

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ pub struct InspectGoal<'a, 'tcx> {
3737
orig_values: &'a [ty::GenericArg<'tcx>],
3838
goal: Goal<'tcx, ty::Predicate<'tcx>>,
3939
evaluation: &'a inspect::GoalEvaluation<'tcx>,
40+
source: GoalSource,
4041
}
4142

4243
pub struct InspectCandidate<'a, 'tcx> {
4344
goal: &'a InspectGoal<'a, 'tcx>,
4445
kind: inspect::ProbeKind<'tcx>,
45-
nested_goals: Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
46+
nested_goals: Vec<(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>)>,
4647
final_state: inspect::CanonicalState<'tcx, ()>,
4748
result: QueryResult<'tcx>,
4849
}
@@ -65,15 +66,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
6566
let param_env = self.goal.goal.param_env;
6667
let mut orig_values = self.goal.orig_values.to_vec();
6768
let mut instantiated_goals = vec![];
68-
for goal in &self.nested_goals {
69+
for &(source, goal) in &self.nested_goals {
6970
let goal = canonical::instantiate_canonical_state(
7071
infcx,
7172
visitor.span(),
7273
param_env,
7374
&mut orig_values,
74-
*goal,
75+
goal,
7576
);
76-
instantiated_goals.push(goal);
77+
instantiated_goals.push((source, goal));
7778
}
7879

7980
let () = canonical::instantiate_canonical_state(
@@ -84,7 +85,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
8485
self.final_state,
8586
);
8687

87-
for &goal in &instantiated_goals {
88+
for (source, goal) in instantiated_goals {
8889
let proof_tree = match goal.predicate.kind().no_bound_vars() {
8990
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
9091
let unconstrained_term = match term.unpack() {
@@ -127,6 +128,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
127128
infcx,
128129
self.goal.depth + 1,
129130
&proof_tree.unwrap(),
131+
source,
130132
)));
131133
}
132134
}
@@ -150,20 +152,27 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
150152
self.goal
151153
}
152154

155+
pub fn source(&self) -> GoalSource {
156+
self.source
157+
}
158+
153159
pub fn result(&self) -> Result<Certainty, NoSolution> {
154160
self.evaluation.evaluation.result.map(|c| c.value.certainty)
155161
}
156162

157163
fn candidates_recur(
158164
&'a self,
159165
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,
160-
nested_goals: &mut Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
166+
nested_goals: &mut Vec<(
167+
GoalSource,
168+
inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>,
169+
)>,
161170
probe: &inspect::Probe<'tcx>,
162171
) {
163172
let num_candidates = candidates.len();
164173
for step in &probe.steps {
165174
match step {
166-
&inspect::ProbeStep::AddGoal(_source, goal) => nested_goals.push(goal),
175+
&inspect::ProbeStep::AddGoal(source, goal) => nested_goals.push((source, goal)),
167176
inspect::ProbeStep::NestedProbe(ref probe) => {
168177
// Nested probes have to prove goals added in their parent
169178
// but do not leak them, so we truncate the added goals
@@ -250,6 +259,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
250259
infcx: &'a InferCtxt<'tcx>,
251260
depth: usize,
252261
root: &'a inspect::GoalEvaluation<'tcx>,
262+
source: GoalSource,
253263
) -> Self {
254264
match root.kind {
255265
inspect::GoalEvaluationKind::Root { ref orig_values } => InspectGoal {
@@ -258,6 +268,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
258268
orig_values,
259269
goal: root.uncanonicalized_goal.fold_with(&mut EagerResolver::new(infcx)),
260270
evaluation: root,
271+
source,
261272
},
262273
inspect::GoalEvaluationKind::Nested { .. } => unreachable!(),
263274
}
@@ -286,6 +297,6 @@ impl<'tcx> InferCtxt<'tcx> {
286297
) -> V::Result {
287298
let (_, proof_tree) = self.evaluate_root_goal(goal, GenerateProofTree::Yes);
288299
let proof_tree = proof_tree.unwrap();
289-
visitor.visit_goal(&InspectGoal::new(self, 0, &proof_tree))
300+
visitor.visit_goal(&InspectGoal::new(self, 0, &proof_tree, GoalSource::Misc))
290301
}
291302
}

0 commit comments

Comments
 (0)