Skip to content

Commit 9178bc0

Browse files
authored
Rollup merge of #104907 - compiler-errors:selcx-infcx, r=oli-obk
Remove `SelectionContext::infcx()` in favor of field access Encapsulation doesn't seem particularly important here, and having two choices is always more confusing than having one. r? types
2 parents 8a84dd8 + 6436c34 commit 9178bc0

File tree

8 files changed

+75
-92
lines changed

8 files changed

+75
-92
lines changed

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -599,17 +599,17 @@ impl<'tcx> AutoTraitFinder<'tcx> {
599599
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
600600
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
601601
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
602-
select: &mut SelectionContext<'_, 'tcx>,
602+
selcx: &mut SelectionContext<'_, 'tcx>,
603603
only_projections: bool,
604604
) -> bool {
605605
let dummy_cause = ObligationCause::dummy();
606606

607607
for obligation in nested {
608608
let is_new_pred =
609-
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate));
609+
fresh_preds.insert(self.clean_pred(selcx.infcx, obligation.predicate));
610610

611611
// Resolve any inference variables that we can, to help selection succeed
612-
let predicate = select.infcx().resolve_vars_if_possible(obligation.predicate);
612+
let predicate = selcx.infcx.resolve_vars_if_possible(obligation.predicate);
613613

614614
// We only add a predicate as a user-displayable bound if
615615
// it involves a generic parameter, and doesn't contain
@@ -717,10 +717,8 @@ impl<'tcx> AutoTraitFinder<'tcx> {
717717
// and turn them into an explicit negative impl for our type.
718718
debug!("Projecting and unifying projection predicate {:?}", predicate);
719719

720-
match project::poly_project_and_unify_type(
721-
select,
722-
&obligation.with(self.tcx, p),
723-
) {
720+
match project::poly_project_and_unify_type(selcx, &obligation.with(self.tcx, p))
721+
{
724722
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
725723
debug!(
726724
"evaluate_nested_obligations: Unable to unify predicate \
@@ -745,7 +743,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
745743
computed_preds,
746744
fresh_preds,
747745
predicates,
748-
select,
746+
selcx,
749747
only_projections,
750748
) {
751749
return false;
@@ -768,7 +766,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
768766
}
769767
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(binder)) => {
770768
let binder = bound_predicate.rebind(binder);
771-
select.infcx().region_outlives_predicate(&dummy_cause, binder)
769+
selcx.infcx.region_outlives_predicate(&dummy_cause, binder)
772770
}
773771
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(binder)) => {
774772
let binder = bound_predicate.rebind(binder);
@@ -777,14 +775,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
777775
binder.map_bound_ref(|pred| pred.0).no_bound_vars(),
778776
) {
779777
(None, Some(t_a)) => {
780-
select.infcx().register_region_obligation_with_cause(
778+
selcx.infcx.register_region_obligation_with_cause(
781779
t_a,
782-
select.infcx().tcx.lifetimes.re_static,
780+
selcx.infcx.tcx.lifetimes.re_static,
783781
&dummy_cause,
784782
);
785783
}
786784
(Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
787-
select.infcx().register_region_obligation_with_cause(
785+
selcx.infcx.register_region_obligation_with_cause(
788786
t_a,
789787
r_b,
790788
&dummy_cause,
@@ -796,13 +794,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
796794
ty::PredicateKind::ConstEquate(c1, c2) => {
797795
let evaluate = |c: ty::Const<'tcx>| {
798796
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
799-
match select.infcx().const_eval_resolve(
797+
match selcx.infcx.const_eval_resolve(
800798
obligation.param_env,
801799
unevaluated,
802800
Some(obligation.cause.span),
803801
) {
804802
Ok(Some(valtree)) => {
805-
Ok(ty::Const::from_value(select.tcx(), valtree, c.ty()))
803+
Ok(ty::Const::from_value(selcx.tcx(), valtree, c.ty()))
806804
}
807805
Ok(None) => {
808806
let tcx = self.tcx;
@@ -823,10 +821,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
823821

824822
match (evaluate(c1), evaluate(c2)) {
825823
(Ok(c1), Ok(c2)) => {
826-
match select
827-
.infcx()
828-
.at(&obligation.cause, obligation.param_env)
829-
.eq(c1, c2)
824+
match selcx.infcx.at(&obligation.cause, obligation.param_env).eq(c1, c2)
830825
{
831826
Ok(_) => (),
832827
Err(_) => return false,

compiler/rustc_trait_selection/src/traits/coherence.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
119119
impl_def_id: DefId,
120120
) -> ty::ImplHeader<'tcx> {
121121
let tcx = selcx.tcx();
122-
let impl_substs = selcx.infcx().fresh_substs_for_item(DUMMY_SP, impl_def_id);
122+
let impl_substs = selcx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
123123

124124
let header = ty::ImplHeader {
125125
impl_def_id,
@@ -149,7 +149,7 @@ fn overlap<'cx, 'tcx>(
149149
impl1_def_id, impl2_def_id, overlap_mode
150150
);
151151

152-
selcx.infcx().probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| {
152+
selcx.infcx.probe_maybe_skip_leak_check(skip_leak_check.is_yes(), |snapshot| {
153153
overlap_within_probe(selcx, impl1_def_id, impl2_def_id, overlap_mode, snapshot)
154154
})
155155
}
@@ -161,7 +161,7 @@ fn overlap_within_probe<'cx, 'tcx>(
161161
overlap_mode: OverlapMode,
162162
snapshot: &CombinedSnapshot<'tcx>,
163163
) -> Option<OverlapResult<'tcx>> {
164-
let infcx = selcx.infcx();
164+
let infcx = selcx.infcx;
165165

166166
if overlap_mode.use_negative_impl() {
167167
if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id)
@@ -200,9 +200,9 @@ fn overlap_within_probe<'cx, 'tcx>(
200200
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
201201

202202
let involves_placeholder =
203-
matches!(selcx.infcx().region_constraints_added_in_snapshot(snapshot), Some(true));
203+
matches!(selcx.infcx.region_constraints_added_in_snapshot(snapshot), Some(true));
204204

205-
let impl_header = selcx.infcx().resolve_vars_if_possible(impl1_header);
205+
let impl_header = selcx.infcx.resolve_vars_if_possible(impl1_header);
206206
Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder })
207207
}
208208

@@ -214,7 +214,7 @@ fn equate_impl_headers<'cx, 'tcx>(
214214
// Do `a` and `b` unify? If not, no overlap.
215215
debug!("equate_impl_headers(impl1_header={:?}, impl2_header={:?}", impl1_header, impl2_header);
216216
selcx
217-
.infcx()
217+
.infcx
218218
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
219219
.eq_impl_headers(impl1_header, impl2_header)
220220
.map(|infer_ok| infer_ok.obligations)
@@ -255,7 +255,7 @@ fn implicit_negative<'cx, 'tcx>(
255255
"implicit_negative(impl1_header={:?}, impl2_header={:?}, obligations={:?})",
256256
impl1_header, impl2_header, obligations
257257
);
258-
let infcx = selcx.infcx();
258+
let infcx = selcx.infcx;
259259
let opt_failing_obligation = impl1_header
260260
.predicates
261261
.iter()

compiler/rustc_trait_selection/src/traits/fulfill.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
199199
// code is so hot. 1 and 0 dominate; 2+ is fairly rare.
200200
1 => {
201201
let infer_var = pending_obligation.stalled_on[0];
202-
self.selcx.infcx().ty_or_const_infer_var_changed(infer_var)
202+
self.selcx.infcx.ty_or_const_infer_var_changed(infer_var)
203203
}
204204
0 => {
205205
// In this case we haven't changed, but wish to make a change.
@@ -210,7 +210,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
210210
// form was a perf win. See #64545 for details.
211211
(|| {
212212
for &infer_var in &pending_obligation.stalled_on {
213-
if self.selcx.infcx().ty_or_const_infer_var_changed(infer_var) {
213+
if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
214214
return true;
215215
}
216216
}
@@ -240,13 +240,12 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
240240
debug!(?obligation, "pre-resolve");
241241

242242
if obligation.predicate.has_non_region_infer() {
243-
obligation.predicate =
244-
self.selcx.infcx().resolve_vars_if_possible(obligation.predicate);
243+
obligation.predicate = self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
245244
}
246245

247246
let obligation = &pending_obligation.obligation;
248247

249-
let infcx = self.selcx.infcx();
248+
let infcx = self.selcx.infcx;
250249

251250
if obligation.predicate.has_projections() {
252251
let mut obligations = Vec::new();
@@ -353,7 +352,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
353352
}
354353

355354
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
356-
match self.selcx.infcx().closure_kind(closure_substs) {
355+
match self.selcx.infcx.closure_kind(closure_substs) {
357356
Some(closure_kind) => {
358357
if closure_kind.extends(kind) {
359358
ProcessResult::Changed(vec![])
@@ -367,7 +366,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
367366

368367
ty::PredicateKind::WellFormed(arg) => {
369368
match wf::obligations(
370-
self.selcx.infcx(),
369+
self.selcx.infcx,
371370
obligation.param_env,
372371
obligation.cause.body_id,
373372
obligation.recursion_depth + 1,
@@ -384,7 +383,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
384383
}
385384

386385
ty::PredicateKind::Subtype(subtype) => {
387-
match self.selcx.infcx().subtype_predicate(
386+
match self.selcx.infcx.subtype_predicate(
388387
&obligation.cause,
389388
obligation.param_env,
390389
Binder::dummy(subtype),
@@ -408,7 +407,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
408407
}
409408

410409
ty::PredicateKind::Coerce(coerce) => {
411-
match self.selcx.infcx().coerce_predicate(
410+
match self.selcx.infcx.coerce_predicate(
412411
&obligation.cause,
413412
obligation.param_env,
414413
Binder::dummy(coerce),
@@ -432,7 +431,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
432431

433432
ty::PredicateKind::ConstEvaluatable(uv) => {
434433
match const_evaluatable::is_const_evaluatable(
435-
self.selcx.infcx(),
434+
self.selcx.infcx,
436435
uv,
437436
obligation.param_env,
438437
obligation.cause.span,
@@ -503,7 +502,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
503502

504503
let mut evaluate = |c: Const<'tcx>| {
505504
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
506-
match self.selcx.infcx().try_const_eval_resolve(
505+
match self.selcx.infcx.try_const_eval_resolve(
507506
obligation.param_env,
508507
unevaluated,
509508
c.ty(),
@@ -531,7 +530,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
531530
(Ok(c1), Ok(c2)) => {
532531
match self
533532
.selcx
534-
.infcx()
533+
.infcx
535534
.at(&obligation.cause, obligation.param_env)
536535
.eq(c1, c2)
537536
{
@@ -601,7 +600,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
601600
trait_obligation: TraitObligation<'tcx>,
602601
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
603602
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
604-
let infcx = self.selcx.infcx();
603+
let infcx = self.selcx.infcx;
605604
if obligation.predicate.is_global() {
606605
// no type variables present, can use evaluation for better caching.
607606
// FIXME: consider caching errors too.
@@ -659,7 +658,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
659658
if obligation.predicate.is_global() {
660659
// no type variables present, can use evaluation for better caching.
661660
// FIXME: consider caching errors too.
662-
if self.selcx.infcx().predicate_must_hold_considering_regions(obligation) {
661+
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
663662
if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate(
664663
&mut self.selcx,
665664
project_obligation.predicate,
@@ -668,7 +667,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
668667
// evaluated all sub-obligations. We can therefore mark the 'root'
669668
// obligation as complete, and skip evaluating sub-obligations.
670669
self.selcx
671-
.infcx()
670+
.infcx
672671
.inner
673672
.borrow_mut()
674673
.projection_cache()
@@ -707,7 +706,7 @@ fn substs_infer_vars<'a, 'tcx>(
707706
substs: ty::Binder<'tcx, SubstsRef<'tcx>>,
708707
) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> {
709708
selcx
710-
.infcx()
709+
.infcx
711710
.resolve_vars_if_possible(substs)
712711
.skip_binder() // ok because this check doesn't care about regions
713712
.iter()

0 commit comments

Comments
 (0)