Skip to content

Commit 6e3808e

Browse files
Store goal source in InspectGoal
1 parent 837bde1 commit 6e3808e

File tree

1 file changed

+27
-12
lines changed
  • compiler/rustc_trait_selection/src/solve/inspect

1 file changed

+27
-12
lines changed

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

+27-12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct InspectGoal<'a, 'tcx> {
4242
result: Result<Certainty, NoSolution>,
4343
evaluation_kind: inspect::CanonicalGoalEvaluationKind<'tcx>,
4444
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
45+
source: GoalSource,
4546
}
4647

4748
/// The expected term of a `NormalizesTo` goal gets replaced
@@ -92,7 +93,7 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
9293
pub struct InspectCandidate<'a, 'tcx> {
9394
goal: &'a InspectGoal<'a, 'tcx>,
9495
kind: inspect::ProbeKind<'tcx>,
95-
nested_goals: Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
96+
nested_goals: Vec<(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>)>,
9697
final_state: inspect::CanonicalState<'tcx, ()>,
9798
result: QueryResult<'tcx>,
9899
shallow_certainty: Certainty,
@@ -145,13 +146,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
145146
let instantiated_goals: Vec<_> = self
146147
.nested_goals
147148
.iter()
148-
.map(|goal| {
149-
canonical::instantiate_canonical_state(
150-
infcx,
151-
span,
152-
param_env,
153-
&mut orig_values,
154-
*goal,
149+
.map(|(source, goal)| {
150+
(
151+
*source,
152+
canonical::instantiate_canonical_state(
153+
infcx,
154+
span,
155+
param_env,
156+
&mut orig_values,
157+
*goal,
158+
),
155159
)
156160
})
157161
.collect();
@@ -173,7 +177,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
173177

174178
instantiated_goals
175179
.into_iter()
176-
.map(|goal| match goal.predicate.kind().no_bound_vars() {
180+
.map(|(source, goal)| match goal.predicate.kind().no_bound_vars() {
177181
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
178182
let unconstrained_term = match term.unpack() {
179183
ty::TermKind::Ty(_) => infcx
@@ -197,13 +201,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
197201
self.goal.depth + 1,
198202
proof_tree.unwrap(),
199203
Some(NormalizesToTermHack { term, unconstrained_term }),
204+
source,
200205
)
201206
}
202207
_ => InspectGoal::new(
203208
infcx,
204209
self.goal.depth + 1,
205210
infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1.unwrap(),
206211
None,
212+
source,
207213
),
208214
})
209215
.collect()
@@ -229,16 +235,23 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
229235
self.result
230236
}
231237

238+
pub fn source(&self) -> GoalSource {
239+
self.source
240+
}
241+
232242
fn candidates_recur(
233243
&'a self,
234244
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,
235-
nested_goals: &mut Vec<inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>>,
245+
nested_goals: &mut Vec<(
246+
GoalSource,
247+
inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>,
248+
)>,
236249
probe: &inspect::Probe<'tcx>,
237250
) {
238251
let mut shallow_certainty = None;
239252
for step in &probe.steps {
240253
match step {
241-
&inspect::ProbeStep::AddGoal(_source, goal) => nested_goals.push(goal),
254+
&inspect::ProbeStep::AddGoal(source, goal) => nested_goals.push((source, goal)),
242255
inspect::ProbeStep::NestedProbe(ref probe) => {
243256
// Nested probes have to prove goals added in their parent
244257
// but do not leak them, so we truncate the added goals
@@ -321,6 +334,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
321334
depth: usize,
322335
root: inspect::GoalEvaluation<'tcx>,
323336
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
337+
source: GoalSource,
324338
) -> Self {
325339
let inspect::GoalEvaluation { uncanonicalized_goal, kind, evaluation } = root;
326340
let inspect::GoalEvaluationKind::Root { orig_values } = kind else { unreachable!() };
@@ -343,6 +357,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
343357
result,
344358
evaluation_kind: evaluation.kind,
345359
normalizes_to_term_hack,
360+
source,
346361
}
347362
}
348363
}
@@ -369,6 +384,6 @@ impl<'tcx> InferCtxt<'tcx> {
369384
) -> V::Result {
370385
let (_, proof_tree) = self.evaluate_root_goal(goal, GenerateProofTree::Yes);
371386
let proof_tree = proof_tree.unwrap();
372-
visitor.visit_goal(&InspectGoal::new(self, 0, proof_tree, None))
387+
visitor.visit_goal(&InspectGoal::new(self, 0, proof_tree, None, GoalSource::Misc))
373388
}
374389
}

0 commit comments

Comments
 (0)