Skip to content

Commit 209103f

Browse files
committed
Remove the final use of old_defining_use_anchor
1 parent 5fcffb6 commit 209103f

File tree

9 files changed

+74
-22
lines changed

9 files changed

+74
-22
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14621462
self.param_env,
14631463
original_values,
14641464
query_result,
1465+
self.defining_use_anchor,
14651466
)
14661467
}
14671468

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,18 @@ impl<'tcx> InferCtxt<'tcx> {
181181
param_env: ty::ParamEnv<'tcx>,
182182
original_values: &OriginalQueryValues<'tcx>,
183183
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
184+
defining_use_anchor: DefiningAnchor,
184185
) -> InferResult<'tcx, R>
185186
where
186187
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
187188
{
188-
let InferOk { value: result_subst, mut obligations } =
189-
self.query_response_substitution(cause, param_env, original_values, query_response)?;
189+
let InferOk { value: result_subst, mut obligations } = self.query_response_substitution(
190+
cause,
191+
param_env,
192+
original_values,
193+
query_response,
194+
defining_use_anchor,
195+
)?;
190196

191197
obligations.extend(self.query_outlives_constraints_into_obligations(
192198
cause,
@@ -243,12 +249,19 @@ impl<'tcx> InferCtxt<'tcx> {
243249
original_values: &OriginalQueryValues<'tcx>,
244250
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
245251
output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
252+
defining_use_anchor: DefiningAnchor,
246253
) -> InferResult<'tcx, R>
247254
where
248255
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
249256
{
250257
let InferOk { value: result_subst, mut obligations } = self
251-
.query_response_substitution_guess(cause, param_env, original_values, query_response)?;
258+
.query_response_substitution_guess(
259+
cause,
260+
param_env,
261+
original_values,
262+
query_response,
263+
defining_use_anchor,
264+
)?;
252265

253266
// Compute `QueryOutlivesConstraint` values that unify each of
254267
// the original values `v_o` that was canonicalized into a
@@ -357,6 +370,7 @@ impl<'tcx> InferCtxt<'tcx> {
357370
param_env: ty::ParamEnv<'tcx>,
358371
original_values: &OriginalQueryValues<'tcx>,
359372
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
373+
defining_use_anchor: DefiningAnchor,
360374
) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
361375
where
362376
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
@@ -371,6 +385,7 @@ impl<'tcx> InferCtxt<'tcx> {
371385
param_env,
372386
original_values,
373387
query_response,
388+
defining_use_anchor,
374389
)?;
375390

376391
value.obligations.extend(
@@ -403,6 +418,7 @@ impl<'tcx> InferCtxt<'tcx> {
403418
param_env: ty::ParamEnv<'tcx>,
404419
original_values: &OriginalQueryValues<'tcx>,
405420
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
421+
defining_use_anchor: DefiningAnchor,
406422
) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
407423
where
408424
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
@@ -504,7 +520,7 @@ impl<'tcx> InferCtxt<'tcx> {
504520
debug!(?a, ?b, "constrain opaque type");
505521
obligations.extend(
506522
self.at(cause, param_env)
507-
.define_opaque_types(self.old_defining_use_anchor)
523+
.define_opaque_types(defining_use_anchor)
508524
.eq(a, b)?
509525
.obligations,
510526
);

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_hir::def_id::DefId;
22
use rustc_infer::infer::at::ToTrace;
33
use rustc_infer::infer::canonical::CanonicalVarValues;
44
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
5-
use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
5+
use rustc_infer::infer::{DefiningAnchor, InferCtxt, InferOk, LateBoundRegionConversionTime};
66
use rustc_infer::traits::query::NoSolution;
77
use rustc_infer::traits::ObligationCause;
88
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
@@ -27,6 +27,7 @@ pub struct EvalCtxt<'a, 'tcx> {
2727
/// This field is used by a debug assertion in [`EvalCtxt::evaluate_goal`],
2828
/// see the comment in that method for more details.
2929
pub in_projection_eq_hack: bool,
30+
pub(super) defining_use_anchor: DefiningAnchor,
3031
}
3132

3233
impl<'tcx> EvalCtxt<'_, 'tcx> {

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
5454
fn select_where_possible(
5555
&mut self,
5656
infcx: &InferCtxt<'tcx>,
57-
_defining_use_anchor: DefiningAnchor,
57+
defining_use_anchor: DefiningAnchor,
5858
) -> Vec<FulfillmentError<'tcx>> {
5959
let mut errors = Vec::new();
6060
for i in 0.. {
@@ -65,7 +65,8 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
6565
let mut has_changed = false;
6666
for obligation in mem::take(&mut self.obligations) {
6767
let goal = obligation.clone().into();
68-
let (changed, certainty) = match infcx.evaluate_root_goal(goal) {
68+
let (changed, certainty) = match infcx.evaluate_root_goal(goal, defining_use_anchor)
69+
{
6970
Ok(result) => result,
7071
Err(NoSolution) => {
7172
errors.push(FulfillmentError {

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::mem;
2020
use rustc_hir::def_id::DefId;
2121
use rustc_infer::infer::canonical::{Canonical, CanonicalVarValues};
2222
use rustc_infer::infer::canonical::{OriginalQueryValues, QueryRegionConstraints, QueryResponse};
23-
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
23+
use rustc_infer::infer::{DefiningAnchor, InferCtxt, InferOk, TyCtxtInferExt};
2424
use rustc_infer::traits::query::NoSolution;
2525
use rustc_infer::traits::Obligation;
2626
use rustc_middle::infer::canonical::Certainty as OldCertainty;
@@ -156,13 +156,15 @@ pub trait InferCtxtEvalExt<'tcx> {
156156
fn evaluate_root_goal(
157157
&self,
158158
goal: Goal<'tcx, ty::Predicate<'tcx>>,
159+
defining_use_anchor: DefiningAnchor,
159160
) -> Result<(bool, Certainty), NoSolution>;
160161
}
161162

162163
impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
163164
fn evaluate_root_goal(
164165
&self,
165166
goal: Goal<'tcx, ty::Predicate<'tcx>>,
167+
defining_use_anchor: DefiningAnchor,
166168
) -> Result<(bool, Certainty), NoSolution> {
167169
let mut search_graph = search_graph::SearchGraph::new(self.tcx);
168170

@@ -171,6 +173,7 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
171173
infcx: self,
172174
var_values: CanonicalVarValues::dummy(),
173175
in_projection_eq_hack: false,
176+
defining_use_anchor,
174177
}
175178
.evaluate_goal(goal);
176179

@@ -194,15 +197,21 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
194197
tcx: TyCtxt<'tcx>,
195198
search_graph: &'a mut search_graph::SearchGraph<'tcx>,
196199
canonical_goal: CanonicalGoal<'tcx>,
200+
defining_use_anchor: DefiningAnchor,
197201
) -> QueryResult<'tcx> {
198202
// Deal with overflow, caching, and coinduction.
199203
//
200204
// The actual solver logic happens in `ecx.compute_goal`.
201205
search_graph.with_new_goal(tcx, canonical_goal, |search_graph| {
202206
let (ref infcx, goal, var_values) =
203207
tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &canonical_goal);
204-
let mut ecx =
205-
EvalCtxt { infcx, var_values, search_graph, in_projection_eq_hack: false };
208+
let mut ecx = EvalCtxt {
209+
infcx,
210+
var_values,
211+
search_graph,
212+
in_projection_eq_hack: false,
213+
defining_use_anchor,
214+
};
206215
ecx.compute_goal(goal)
207216
})
208217
}
@@ -225,12 +234,20 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
225234
) -> Result<(bool, Certainty), NoSolution> {
226235
let mut orig_values = OriginalQueryValues::default();
227236
let canonical_goal = self.infcx.canonicalize_query(goal, &mut orig_values);
228-
let canonical_response =
229-
EvalCtxt::evaluate_canonical_goal(self.tcx(), self.search_graph, canonical_goal)?;
237+
let canonical_response = EvalCtxt::evaluate_canonical_goal(
238+
self.tcx(),
239+
self.search_graph,
240+
canonical_goal,
241+
self.defining_use_anchor,
242+
)?;
230243

231244
let has_changed = !canonical_response.value.var_values.is_identity();
232-
let certainty =
233-
instantiate_canonical_query_response(self.infcx, &orig_values, canonical_response);
245+
let certainty = instantiate_canonical_query_response(
246+
self.infcx,
247+
&orig_values,
248+
canonical_response,
249+
self.defining_use_anchor,
250+
);
234251

235252
// Check that rerunning this query with its inference constraints applied
236253
// doesn't result in new inference constraints and has the same result.
@@ -246,8 +263,12 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
246263
{
247264
let mut orig_values = OriginalQueryValues::default();
248265
let canonical_goal = self.infcx.canonicalize_query(goal, &mut orig_values);
249-
let canonical_response =
250-
EvalCtxt::evaluate_canonical_goal(self.tcx(), self.search_graph, canonical_goal)?;
266+
let canonical_response = EvalCtxt::evaluate_canonical_goal(
267+
self.tcx(),
268+
self.search_graph,
269+
canonical_goal,
270+
self.defining_use_anchor,
271+
)?;
251272
if !canonical_response.value.var_values.is_identity() {
252273
bug!("unstable result: {goal:?} {canonical_goal:?} {canonical_response:?}");
253274
}
@@ -580,6 +601,7 @@ fn instantiate_canonical_query_response<'tcx>(
580601
infcx: &InferCtxt<'tcx>,
581602
original_values: &OriginalQueryValues<'tcx>,
582603
response: CanonicalResponse<'tcx>,
604+
defining_use_anchor: DefiningAnchor,
583605
) -> Certainty {
584606
let Ok(InferOk { value, obligations }) = infcx
585607
.instantiate_query_response_and_region_obligations(
@@ -599,6 +621,7 @@ fn instantiate_canonical_query_response<'tcx>(
599621
opaque_types: resp.external_constraints.opaque_types.to_owned(),
600622
value: resp.certainty,
601623
}),
624+
defining_use_anchor,
602625
) else { bug!(); };
603626
assert!(obligations.is_empty());
604627
value

compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
5858
fn select_where_possible(
5959
&mut self,
6060
infcx: &InferCtxt<'tcx>,
61-
_defining_use_anchor: DefiningAnchor,
61+
defining_use_anchor: DefiningAnchor,
6262
) -> Vec<FulfillmentError<'tcx>> {
6363
if !self.usable_in_snapshot {
6464
assert!(!infcx.is_in_snapshot());
@@ -95,6 +95,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
9595
obligation.param_env,
9696
&orig_values,
9797
&response,
98+
defining_use_anchor,
9899
) {
99100
Ok(infer_ok) => next_round.extend(
100101
infer_ok.obligations.into_iter().map(|obligation| {

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
8787
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
8888
} else {
8989
self.probe(|snapshot| {
90-
if let Ok((_, certainty)) =
91-
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate))
92-
{
90+
if let Ok((_, certainty)) = self.evaluate_root_goal(
91+
Goal::new(self.tcx, param_env, obligation.predicate),
92+
rustc_infer::infer::DefiningAnchor::Error,
93+
) {
9394
match certainty {
9495
Certainty::Yes => {
9596
if self.opaque_types_added_in_snapshot(snapshot) {

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::traits::project::{needs_normalization, BoundVarReplacer, PlaceholderR
1010
use crate::traits::{ObligationCause, PredicateObligation, Reveal};
1111
use rustc_data_structures::sso::SsoHashMap;
1212
use rustc_data_structures::stack::ensure_sufficient_stack;
13+
use rustc_infer::infer::DefiningAnchor;
1314
use rustc_infer::traits::Normalized;
1415
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
1516
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt};
@@ -72,6 +73,7 @@ impl<'cx, 'tcx> QueryNormalizeExt<'tcx> for At<'cx, 'tcx> {
7273
cache: SsoHashMap::new(),
7374
anon_depth: 0,
7475
universes: vec![],
76+
defining_use_anchor: self.define_opaque_types,
7577
};
7678

7779
// This is actually a consequence by the way `normalize_erasing_regions` works currently.
@@ -168,6 +170,7 @@ struct QueryNormalizer<'cx, 'tcx> {
168170
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
169171
anon_depth: usize,
170172
universes: Vec<Option<ty::UniverseIndex>>,
173+
defining_use_anchor: DefiningAnchor,
171174
}
172175

173176
impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx> {
@@ -282,6 +285,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
282285
self.param_env,
283286
&orig_values,
284287
result,
288+
self.defining_use_anchor,
285289
)?;
286290
debug!("QueryNormalizer: result = {:#?}", result);
287291
debug!("QueryNormalizer: obligations = {:#?}", obligations);
@@ -333,6 +337,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
333337
self.param_env,
334338
&orig_values,
335339
result,
340+
self.defining_use_anchor,
336341
)?;
337342
debug!("QueryNormalizer: result = {:#?}", result);
338343
debug!("QueryNormalizer: obligations = {:#?}", obligations);

compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Copy + TypeFoldable<TyCtxt<'tcx>> + 't
8585
query_key: ParamEnvAnd<'tcx, Self>,
8686
infcx: &InferCtxt<'tcx>,
8787
output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
88+
defining_use_anchor: DefiningAnchor,
8889
) -> Fallible<(
8990
Self::QueryResponse,
9091
Option<Canonical<'tcx, ParamEnvAnd<'tcx, Self>>>,
@@ -112,6 +113,7 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Copy + TypeFoldable<TyCtxt<'tcx>> + 't
112113
&canonical_var_values,
113114
canonical_result,
114115
output_query_region_constraints,
116+
defining_use_anchor,
115117
)?;
116118

117119
Ok((value, Some(canonical_self), obligations, canonical_result.value.certainty))
@@ -128,11 +130,11 @@ where
128130
fn fully_perform(
129131
self,
130132
infcx: &InferCtxt<'tcx>,
131-
_defining_use_anchor: DefiningAnchor,
133+
defining_use_anchor: DefiningAnchor,
132134
) -> Fallible<TypeOpOutput<'tcx, Self>> {
133135
let mut region_constraints = QueryRegionConstraints::default();
134136
let (output, error_info, mut obligations, _) =
135-
Q::fully_perform_into(self, infcx, &mut region_constraints)?;
137+
Q::fully_perform_into(self, infcx, &mut region_constraints, defining_use_anchor)?;
136138

137139
// Typically, instantiating NLL query results does not
138140
// create obligations. However, in some cases there
@@ -148,6 +150,7 @@ where
148150
obligation.param_env.and(ProvePredicate::new(obligation.predicate)),
149151
infcx,
150152
&mut region_constraints,
153+
defining_use_anchor,
151154
) {
152155
Ok(((), _, new, certainty)) => {
153156
obligations.extend(new);

0 commit comments

Comments
 (0)