Skip to content

Commit 50a5da1

Browse files
EvalCtxt::tcx() -> EvalCtxt::interner()
1 parent f989d2f commit 50a5da1

File tree

13 files changed

+108
-92
lines changed

13 files changed

+108
-92
lines changed

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
2626
&mut self,
2727
goal: Goal<'tcx, (ty::Term<'tcx>, ty::Term<'tcx>, ty::AliasRelationDirection)>,
2828
) -> QueryResult<'tcx> {
29-
let tcx = self.tcx();
29+
let tcx = self.interner();
3030
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3131
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
3232

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(super) trait GoalKind<'tcx>:
8383
assumption: ty::Clause<'tcx>,
8484
) -> Result<Candidate<'tcx>, NoSolution> {
8585
Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
86-
let tcx = ecx.tcx();
86+
let tcx = ecx.interner();
8787
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
8888
bug!("expected object type in `probe_and_consider_object_bound_candidate`");
8989
};
@@ -288,8 +288,10 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
288288
return self.forced_ambiguity(MaybeCause::Ambiguity).into_iter().collect();
289289
}
290290

291-
let goal: Goal<'tcx, G> =
292-
goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty));
291+
let goal: Goal<'tcx, G> = goal.with(
292+
self.interner(),
293+
goal.predicate.with_self_ty(self.interner(), normalized_self_ty),
294+
);
293295
// Vars that show up in the rest of the goal substs may have been constrained by
294296
// normalizing the self type as well, since type variables are not uniquified.
295297
let goal = self.resolve_vars_if_possible(goal);
@@ -339,7 +341,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
339341
goal: Goal<'tcx, G>,
340342
candidates: &mut Vec<Candidate<'tcx>>,
341343
) {
342-
let tcx = self.tcx();
344+
let tcx = self.interner();
343345
let self_ty = goal.predicate.self_ty();
344346
let trait_impls = tcx.trait_impls_of(goal.predicate.trait_def_id(tcx));
345347
let mut consider_impls_for_simplified_type = |simp| {
@@ -455,7 +457,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
455457
goal: Goal<'tcx, G>,
456458
candidates: &mut Vec<Candidate<'tcx>>,
457459
) {
458-
let tcx = self.tcx();
460+
let tcx = self.interner();
459461
let trait_impls = tcx.trait_impls_of(goal.predicate.trait_def_id(tcx));
460462
for &impl_def_id in trait_impls.blanket_impls() {
461463
// For every `default impl`, there's always a non-default `impl`
@@ -478,7 +480,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
478480
goal: Goal<'tcx, G>,
479481
candidates: &mut Vec<Candidate<'tcx>>,
480482
) {
481-
let tcx = self.tcx();
483+
let tcx = self.interner();
482484
let lang_items = tcx.lang_items();
483485
let trait_def_id = goal.predicate.trait_def_id(tcx);
484486

@@ -505,9 +507,9 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
505507
G::consider_builtin_pointer_like_candidate(self, goal)
506508
} else if lang_items.fn_ptr_trait() == Some(trait_def_id) {
507509
G::consider_builtin_fn_ptr_trait_candidate(self, goal)
508-
} else if let Some(kind) = self.tcx().fn_trait_kind_from_def_id(trait_def_id) {
510+
} else if let Some(kind) = self.interner().fn_trait_kind_from_def_id(trait_def_id) {
509511
G::consider_builtin_fn_trait_candidates(self, goal, kind)
510-
} else if let Some(kind) = self.tcx().async_fn_trait_kind_from_def_id(trait_def_id) {
512+
} else if let Some(kind) = self.interner().async_fn_trait_kind_from_def_id(trait_def_id) {
511513
G::consider_builtin_async_fn_trait_candidates(self, goal, kind)
512514
} else if lang_items.async_fn_kind_helper() == Some(trait_def_id) {
513515
G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
@@ -634,7 +636,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
634636

635637
ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty),
636638
ty::Alias(ty::Inherent | ty::Weak, _) => {
637-
self.tcx().sess.dcx().span_delayed_bug(
639+
self.interner().sess.dcx().span_delayed_bug(
638640
DUMMY_SP,
639641
format!("could not normalize {self_ty}, it is not WF"),
640642
);
@@ -643,7 +645,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
643645
};
644646

645647
for assumption in
646-
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
648+
self.interner().item_bounds(alias_ty.def_id).instantiate(self.interner(), alias_ty.args)
647649
{
648650
candidates.extend(G::probe_and_consider_implied_clause(
649651
self,
@@ -673,7 +675,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
673675
goal: Goal<'tcx, G>,
674676
candidates: &mut Vec<Candidate<'tcx>>,
675677
) {
676-
let tcx = self.tcx();
678+
let tcx = self.interner();
677679
if !tcx.trait_def(goal.predicate.trait_def_id(tcx)).implement_via_object {
678680
return;
679681
}
@@ -764,7 +766,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
764766
goal: Goal<'tcx, G>,
765767
candidates: &mut Vec<Candidate<'tcx>>,
766768
) {
767-
let tcx = self.tcx();
769+
let tcx = self.interner();
768770

769771
candidates.extend(self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(
770772
|ecx| {
@@ -793,7 +795,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
793795
goal: Goal<'tcx, G>,
794796
candidates: &mut Vec<Candidate<'tcx>>,
795797
) {
796-
let tcx = self.tcx();
798+
let tcx = self.interner();
797799
let trait_goal: Goal<'tcx, ty::TraitPredicate<'tcx>> =
798800
goal.with(tcx, goal.predicate.trait_ref(tcx));
799801

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
2222
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
2323
ty: Ty<'tcx>,
2424
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
25-
let tcx = ecx.tcx();
25+
let tcx = ecx.interner();
2626
match *ty.kind() {
2727
ty::Uint(_)
2828
| ty::Int(_)
@@ -75,7 +75,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
7575
}
7676

7777
ty::CoroutineWitness(def_id, args) => Ok(ecx
78-
.tcx()
78+
.interner()
7979
.bound_coroutine_hidden_types(def_id)
8080
.map(|bty| bty.instantiate(tcx, args))
8181
.collect()),
@@ -151,8 +151,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
151151
// "best effort" optimization and `sized_constraint` may return `Some`, even
152152
// if the ADT is sized for all possible args.
153153
ty::Adt(def, args) => {
154-
if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) {
155-
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))])
154+
if let Some(sized_crit) = def.sized_constraint(ecx.interner()) {
155+
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.interner(), args))])
156156
} else {
157157
Ok(vec![])
158158
}
@@ -210,10 +210,10 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
210210

211211
// only when `coroutine_clone` is enabled and the coroutine is movable
212212
// impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses)
213-
ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_movability(def_id) {
213+
ty::Coroutine(def_id, args) => match ecx.interner().coroutine_movability(def_id) {
214214
Movability::Static => Err(NoSolution),
215215
Movability::Movable => {
216-
if ecx.tcx().features().coroutine_clone {
216+
if ecx.interner().features().coroutine_clone {
217217
let coroutine = args.as_coroutine();
218218
Ok(vec![
219219
ty::Binder::dummy(coroutine.tupled_upvars_ty()),
@@ -227,9 +227,9 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
227227

228228
// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
229229
ty::CoroutineWitness(def_id, args) => Ok(ecx
230-
.tcx()
230+
.interner()
231231
.bound_coroutine_hidden_types(def_id)
232-
.map(|bty| bty.instantiate(ecx.tcx(), args))
232+
.map(|bty| bty.instantiate(ecx.interner(), args))
233233
.collect()),
234234
}
235235
}
@@ -666,7 +666,7 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
666666
trait_ref: ty::TraitRef<'tcx>,
667667
object_bound: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
668668
) -> Vec<Goal<'tcx, ty::Predicate<'tcx>>> {
669-
let tcx = ecx.tcx();
669+
let tcx = ecx.interner();
670670
let mut requirements = vec![];
671671
requirements.extend(
672672
tcx.super_predicates_of(trait_ref.def_id).instantiate(tcx, trait_ref.args).predicates,
@@ -722,7 +722,7 @@ struct ReplaceProjectionWith<'a, 'tcx> {
722722

723723
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
724724
fn interner(&self) -> TyCtxt<'tcx> {
725-
self.ecx.tcx()
725+
self.ecx.interner()
726726
}
727727

728728
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
@@ -739,7 +739,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
739739
.eq_and_get_goals(
740740
self.param_env,
741741
alias_ty,
742-
proj.projection_term.expect_ty(self.ecx.tcx()),
742+
proj.projection_term.expect_ty(self.ecx.interner()),
743743
)
744744
.expect("expected to be able to unify goal projection with dyn's projection"),
745745
);

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
7171
QueryInput {
7272
goal,
7373
predefined_opaques_in_body: self
74-
.tcx()
74+
.interner()
7575
.mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types }),
7676
},
7777
);
@@ -144,7 +144,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
144144
Response {
145145
var_values,
146146
certainty,
147-
external_constraints: self.tcx().mk_external_constraints(external_constraints),
147+
external_constraints: self.interner().mk_external_constraints(external_constraints),
148148
},
149149
);
150150

@@ -160,7 +160,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
160160
maybe_cause: MaybeCause,
161161
) -> CanonicalResponse<'tcx> {
162162
response_no_constraints_raw(
163-
self.tcx(),
163+
self.interner(),
164164
self.max_input_universe,
165165
self.variables,
166166
Certainty::Maybe(maybe_cause),
@@ -194,7 +194,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
194194
let region_obligations = self.infcx.inner.borrow().region_obligations().to_owned();
195195
let mut region_constraints = self.infcx.with_region_constraints(|region_constraints| {
196196
make_query_region_constraints(
197-
self.tcx(),
197+
self.interner(),
198198
region_obligations.iter().map(|r_o| {
199199
(r_o.sup_type, r_o.sub_region, r_o.origin.to_constraint_category())
200200
}),
@@ -239,7 +239,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
239239
);
240240

241241
let Response { var_values, external_constraints, certainty } =
242-
response.instantiate(self.tcx(), &instantiation);
242+
response.instantiate(self.interner(), &instantiation);
243243

244244
Self::unify_query_var_values(self.infcx, param_env, &original_values, var_values);
245245

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
347347
let mut goal_evaluation =
348348
self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind);
349349
let canonical_response = EvalCtxt::evaluate_canonical_goal(
350-
self.tcx(),
350+
self.interner(),
351351
self.search_graph,
352352
canonical_goal,
353353
&mut goal_evaluation,
@@ -450,7 +450,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
450450
}
451451
} else {
452452
self.infcx.enter_forall(kind, |kind| {
453-
let goal = goal.with(self.tcx(), ty::Binder::dummy(kind));
453+
let goal = goal.with(self.interner(), ty::Binder::dummy(kind));
454454
self.add_goal(GoalSource::InstantiateHigherRanked, goal);
455455
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
456456
})
@@ -511,7 +511,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
511511
///
512512
/// Goals for the next step get directly added to the nested goals of the `EvalCtxt`.
513513
fn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution> {
514-
let tcx = self.tcx();
514+
let tcx = self.interner();
515515
let mut goals = core::mem::take(&mut self.nested_goals);
516516

517517
// If this loop did not result in any progress, what's our final certainty.
@@ -597,11 +597,13 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
597597
}
598598
}
599599

600-
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
601-
pub(super) fn tcx(&self) -> TyCtxt<'tcx> {
602-
self.infcx.tcx
600+
impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> EvalCtxt<'_, Infcx> {
601+
pub(super) fn interner(&self) -> I {
602+
self.infcx.interner()
603603
}
604+
}
604605

606+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
605607
pub(super) fn next_ty_infer(&mut self) -> Ty<'tcx> {
606608
let ty = self.infcx.next_ty_var(DUMMY_SP);
607609
self.inspect.add_var_value(ty);
@@ -759,7 +761,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
759761
// NOTE: this check is purely an optimization, the structural eq would
760762
// always fail if the term is not an inference variable.
761763
if term.is_infer() {
762-
let tcx = self.tcx();
764+
let tcx = self.interner();
763765
// We need to relate `alias` to `term` treating only the outermost
764766
// constructor as rigid, relating any contained generic arguments as
765767
// normal. We do this by first structurally equating the `term`
@@ -1054,10 +1056,10 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
10541056
) -> Option<ty::Const<'tcx>> {
10551057
use rustc_middle::mir::interpret::ErrorHandled;
10561058
match self.infcx.const_eval_resolve(param_env, unevaluated, DUMMY_SP) {
1057-
Ok(Some(val)) => Some(ty::Const::new_value(self.tcx(), val, ty)),
1059+
Ok(Some(val)) => Some(ty::Const::new_value(self.interner(), val, ty)),
10581060
Ok(None) | Err(ErrorHandled::TooGeneric(_)) => None,
10591061
Err(ErrorHandled::Reported(e, _)) => {
1060-
Some(ty::Const::new_error(self.tcx(), e.into(), ty))
1062+
Some(ty::Const::new_error(self.interner(), e.into(), ty))
10611063
}
10621064
}
10631065
}
@@ -1070,7 +1072,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
10701072
principal: ty::PolyTraitRef<'tcx>,
10711073
mut supertrait_visitor: impl FnMut(&mut Self, ty::PolyTraitRef<'tcx>, usize, Option<usize>),
10721074
) {
1073-
let tcx = self.tcx();
1075+
let tcx = self.interner();
10741076
let mut offset = 0;
10751077
prepare_vtable_segments::<()>(tcx, principal, |segment| {
10761078
match segment {

compiler/rustc_trait_selection/src/solve/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
133133
}
134134

135135
fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx> {
136-
if self.tcx().check_is_object_safe(trait_def_id) {
136+
if self.interner().check_is_object_safe(trait_def_id) {
137137
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
138138
} else {
139139
Err(NoSolution)
@@ -274,7 +274,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
274274
if let ty::Alias(..) = ty.kind() {
275275
let normalized_ty = self.next_ty_infer();
276276
let alias_relate_goal = Goal::new(
277-
self.tcx(),
277+
self.interner(),
278278
param_env,
279279
ty::PredicateKind::AliasRelate(
280280
ty.into(),

compiler/rustc_trait_selection/src/solve/normalizes_to/anon_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
1212
if let Some(normalized_const) = self.try_const_eval_resolve(
1313
goal.param_env,
1414
ty::UnevaluatedConst::new(goal.predicate.alias.def_id, goal.predicate.alias.args),
15-
self.tcx()
15+
self.interner()
1616
.type_of(goal.predicate.alias.def_id)
1717
.no_bound_vars()
1818
.expect("const ty should not rely on other generics"),

compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
1515
&mut self,
1616
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
1717
) -> QueryResult<'tcx> {
18-
let tcx = self.tcx();
18+
let tcx = self.interner();
1919
let inherent = goal.predicate.alias.expect_ty(tcx);
2020

2121
let impl_def_id = tcx.parent(inherent.def_id);

0 commit comments

Comments
 (0)