Skip to content

Commit 7597d15

Browse files
Split out instantiate_nested_goals
1 parent 13825dc commit 7597d15

File tree

1 file changed

+43
-36
lines changed
  • compiler/rustc_trait_selection/src/solve/inspect

1 file changed

+43
-36
lines changed

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

+43-36
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
5757
self.result.map(|c| c.value.certainty)
5858
}
5959

60+
pub fn goal(&self) -> &'a InspectGoal<'a, 'tcx> {
61+
self.goal
62+
}
63+
6064
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
6165
///
6266
/// If this certainty is `Yes`, then we must be confident that the candidate
@@ -74,46 +78,55 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
7478
/// the state of the `infcx`.
7579
pub fn visit_nested_no_probe<V: ProofTreeVisitor<'tcx>>(&self, visitor: &mut V) -> V::Result {
7680
if self.goal.depth < visitor.config().max_depth {
77-
let infcx = self.goal.infcx;
78-
let param_env = self.goal.goal.param_env;
79-
let mut orig_values = self.goal.orig_values.to_vec();
80-
let mut instantiated_goals = vec![];
81-
for goal in &self.nested_goals {
82-
let goal = canonical::instantiate_canonical_state(
81+
for goal in self.instantiate_nested_goals(visitor.span()) {
82+
try_visit!(visitor.visit_goal(&goal));
83+
}
84+
}
85+
86+
V::Result::output()
87+
}
88+
89+
/// Instantiate the nested goals for the candidate without rolling back their
90+
/// inference constraints. This function modifies the state of the `infcx`.
91+
pub fn instantiate_nested_goals(&self, span: Span) -> Vec<InspectGoal<'a, 'tcx>> {
92+
let infcx = self.goal.infcx;
93+
let param_env = self.goal.goal.param_env;
94+
let mut orig_values = self.goal.orig_values.to_vec();
95+
let instantiated_goals: Vec<_> = self
96+
.nested_goals
97+
.iter()
98+
.map(|goal| {
99+
canonical::instantiate_canonical_state(
83100
infcx,
84-
visitor.span(),
101+
span,
85102
param_env,
86103
&mut orig_values,
87104
*goal,
88-
);
89-
instantiated_goals.push(goal);
90-
}
105+
)
106+
})
107+
.collect();
91108

92-
let () = canonical::instantiate_canonical_state(
93-
infcx,
94-
visitor.span(),
95-
param_env,
96-
&mut orig_values,
97-
self.final_state,
98-
);
109+
let () = canonical::instantiate_canonical_state(
110+
infcx,
111+
span,
112+
param_env,
113+
&mut orig_values,
114+
self.final_state,
115+
);
99116

100-
for &goal in &instantiated_goals {
117+
instantiated_goals
118+
.into_iter()
119+
.map(|goal| {
101120
let proof_tree = match goal.predicate.kind().no_bound_vars() {
102121
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
103122
let unconstrained_term = match term.unpack() {
104123
ty::TermKind::Ty(_) => infcx
105-
.next_ty_var(TypeVariableOrigin {
106-
param_def_id: None,
107-
span: visitor.span(),
108-
})
124+
.next_ty_var(TypeVariableOrigin { param_def_id: None, span })
109125
.into(),
110126
ty::TermKind::Const(ct) => infcx
111127
.next_const_var(
112128
ct.ty(),
113-
ConstVariableOrigin {
114-
param_def_id: None,
115-
span: visitor.span(),
116-
},
129+
ConstVariableOrigin { param_def_id: None, span },
117130
)
118131
.into(),
119132
};
@@ -129,22 +142,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
129142
})
130143
.1;
131144
let InferOk { value: (), obligations: _ } = infcx
132-
.at(&ObligationCause::dummy(), param_env)
145+
.at(&ObligationCause::dummy_with_span(span), param_env)
133146
.eq(DefineOpaqueTypes::Yes, term, unconstrained_term)
134147
.unwrap();
135148
proof_tree
136149
}
137150
_ => infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1,
138151
};
139-
try_visit!(visitor.visit_goal(&InspectGoal::new(
140-
infcx,
141-
self.goal.depth + 1,
142-
proof_tree.unwrap(),
143-
)));
144-
}
145-
}
146-
147-
V::Result::output()
152+
InspectGoal::new(infcx, self.goal.depth + 1, proof_tree.unwrap())
153+
})
154+
.collect()
148155
}
149156

150157
/// Visit all nested goals of this candidate, rolling back

0 commit comments

Comments
 (0)