Skip to content

Commit 8e139ee

Browse files
committed
slight refactor, add comment
1 parent 8024c69 commit 8e139ee

File tree

1 file changed

+20
-11
lines changed
  • compiler/rustc_trait_selection/src/solve/inspect

1 file changed

+20
-11
lines changed

Diff for: compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
123123
&inspect::ProbeStep::AddGoal(goal) => nested_goals.push(goal),
124124
inspect::ProbeStep::EvaluateGoals(_) => (),
125125
inspect::ProbeStep::NestedProbe(ref probe) => {
126+
// Nested probes have to prove goals added in their parent
127+
// but do not leak them, so we truncate the added goals
128+
// afterwards.
126129
let num_goals = nested_goals.len();
127130
self.candidates_recur(candidates, nested_goals, probe);
128131
nested_goals.truncate(num_goals);
@@ -131,10 +134,25 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
131134
}
132135

133136
match probe.kind {
134-
inspect::ProbeKind::Root { result: _ }
135-
| inspect::ProbeKind::NormalizedSelfTyAssembly
137+
inspect::ProbeKind::NormalizedSelfTyAssembly
136138
| inspect::ProbeKind::UnsizeAssembly
137139
| inspect::ProbeKind::UpcastProjectionCompatibility => (),
140+
// We add a candidate for the root evaluation if there
141+
// is only one way to prove a given goal, e.g. for `WellFormed`.
142+
//
143+
// FIXME: This is currently wrong if we don't even try any
144+
// candidates, e.g. for a trait goal, as in this case `candidates` is
145+
// actually supposed to be empty.
146+
inspect::ProbeKind::Root { result: _ } => {
147+
if candidates.is_empty() {
148+
candidates.push(InspectCandidate {
149+
goal: self,
150+
kind: probe.kind,
151+
nested_goals: nested_goals.clone(),
152+
result,
153+
});
154+
}
155+
}
138156
inspect::ProbeKind::MiscCandidate { name: _, result }
139157
| inspect::ProbeKind::TraitCandidate { source: _, result } => {
140158
candidates.push(InspectCandidate {
@@ -167,15 +185,6 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
167185
let mut nested_goals = vec![];
168186
self.candidates_recur(&mut candidates, &mut nested_goals, &last_eval_step.evaluation);
169187

170-
if candidates.is_empty() {
171-
candidates.push(InspectCandidate {
172-
goal: self,
173-
kind: last_eval_step.evaluation.kind,
174-
nested_goals,
175-
result: self.evaluation.evaluation.result,
176-
});
177-
}
178-
179188
candidates
180189
}
181190

0 commit comments

Comments
 (0)