Skip to content

Commit a479f23

Browse files
committed
Don't pass InferCtxt to WfPredicates
1 parent 2d15f1c commit a479f23

File tree

1 file changed

+29
-23
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+29
-23
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

+29-23
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ pub fn obligations<'a, 'tcx>(
6060
GenericArgKind::Lifetime(..) => return Some(Vec::new()),
6161
};
6262

63-
let mut wf =
64-
WfPredicates { infcx, param_env, body_id, span, out: vec![], recursion_depth, item: None };
63+
let mut wf = WfPredicates {
64+
tcx: infcx.tcx,
65+
param_env,
66+
body_id,
67+
span,
68+
out: vec![],
69+
recursion_depth,
70+
item: None,
71+
};
6572
wf.compute(arg);
6673
debug!("wf::obligations({:?}, body_id={:?}) = {:?}", arg, body_id, wf.out);
6774

68-
let result = wf.normalize();
75+
let result = wf.normalize(infcx);
6976
debug!("wf::obligations({:?}, body_id={:?}) ~~> {:?}", arg, body_id, result);
7077
Some(result)
7178
}
@@ -83,7 +90,7 @@ pub fn trait_obligations<'a, 'tcx>(
8390
item: &'tcx hir::Item<'tcx>,
8491
) -> Vec<traits::PredicateObligation<'tcx>> {
8592
let mut wf = WfPredicates {
86-
infcx,
93+
tcx: infcx.tcx,
8794
param_env,
8895
body_id,
8996
span,
@@ -93,7 +100,7 @@ pub fn trait_obligations<'a, 'tcx>(
93100
};
94101
wf.compute_trait_ref(trait_ref, Elaborate::All);
95102
debug!(obligations = ?wf.out);
96-
wf.normalize()
103+
wf.normalize(infcx)
97104
}
98105

99106
pub fn predicate_obligations<'a, 'tcx>(
@@ -104,7 +111,7 @@ pub fn predicate_obligations<'a, 'tcx>(
104111
span: Span,
105112
) -> Vec<traits::PredicateObligation<'tcx>> {
106113
let mut wf = WfPredicates {
107-
infcx,
114+
tcx: infcx.tcx,
108115
param_env,
109116
body_id,
110117
span,
@@ -159,11 +166,11 @@ pub fn predicate_obligations<'a, 'tcx>(
159166
}
160167
}
161168

162-
wf.normalize()
169+
wf.normalize(infcx)
163170
}
164171

165-
struct WfPredicates<'a, 'tcx> {
166-
infcx: &'a InferCtxt<'a, 'tcx>,
172+
struct WfPredicates<'tcx> {
173+
tcx: TyCtxt<'tcx>,
167174
param_env: ty::ParamEnv<'tcx>,
168175
body_id: hir::HirId,
169176
span: Span,
@@ -260,18 +267,17 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
260267
}
261268
}
262269

263-
impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
270+
impl<'tcx> WfPredicates<'tcx> {
264271
fn tcx(&self) -> TyCtxt<'tcx> {
265-
self.infcx.tcx
272+
self.tcx
266273
}
267274

268275
fn cause(&self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
269276
traits::ObligationCause::new(self.span, self.body_id, code)
270277
}
271278

272-
fn normalize(mut self) -> Vec<traits::PredicateObligation<'tcx>> {
279+
fn normalize(self, infcx: &InferCtxt<'_, 'tcx>) -> Vec<traits::PredicateObligation<'tcx>> {
273280
let cause = self.cause(traits::WellFormed(None));
274-
let infcx = &mut self.infcx;
275281
let param_env = self.param_env;
276282
let mut obligations = Vec::with_capacity(self.out.len());
277283
for mut obligation in self.out {
@@ -296,7 +302,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
296302

297303
/// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
298304
fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elaborate) {
299-
let tcx = self.infcx.tcx;
305+
let tcx = self.tcx;
300306
let obligations = self.nominal_obligations(trait_ref.def_id, trait_ref.substs);
301307

302308
debug!("compute_trait_ref obligations {:?}", obligations);
@@ -410,14 +416,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
410416
if !subty.has_escaping_bound_vars() {
411417
let cause = self.cause(cause);
412418
let trait_ref = ty::TraitRef {
413-
def_id: self.infcx.tcx.require_lang_item(LangItem::Sized, None),
414-
substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
419+
def_id: self.tcx.require_lang_item(LangItem::Sized, None),
420+
substs: self.tcx.mk_substs_trait(subty, &[]),
415421
};
416422
self.out.push(traits::Obligation::with_depth(
417423
cause,
418424
self.recursion_depth,
419425
self.param_env,
420-
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.infcx.tcx),
426+
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx),
421427
));
422428
}
423429
}
@@ -617,7 +623,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
617623
// of whatever returned this exact `impl Trait`.
618624

619625
// for named opaque `impl Trait` types we still need to check them
620-
if ty::is_impl_trait_defn(self.infcx.tcx, did).is_none() {
626+
if ty::is_impl_trait_defn(self.tcx, did).is_none() {
621627
let obligations = self.nominal_obligations(did, substs);
622628
self.out.extend(obligations);
623629
}
@@ -683,15 +689,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
683689
def_id: DefId,
684690
substs: SubstsRef<'tcx>,
685691
) -> Vec<traits::PredicateObligation<'tcx>> {
686-
let predicates = self.infcx.tcx.predicates_of(def_id);
692+
let predicates = self.tcx.predicates_of(def_id);
687693
let mut origins = vec![def_id; predicates.predicates.len()];
688694
let mut head = predicates;
689695
while let Some(parent) = head.parent {
690-
head = self.infcx.tcx.predicates_of(parent);
696+
head = self.tcx.predicates_of(parent);
691697
origins.extend(iter::repeat(parent).take(head.predicates.len()));
692698
}
693699

694-
let predicates = predicates.instantiate(self.infcx.tcx, substs);
700+
let predicates = predicates.instantiate(self.tcx, substs);
695701
debug_assert_eq!(predicates.predicates.len(), origins.len());
696702

697703
iter::zip(iter::zip(predicates.predicates, predicates.spans), origins.into_iter().rev())
@@ -746,7 +752,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
746752
// Note: in fact we only permit builtin traits, not `Bar<'d>`, I
747753
// am looking forward to the future here.
748754
if !data.has_escaping_bound_vars() && !region.has_escaping_bound_vars() {
749-
let implicit_bounds = object_region_bounds(self.infcx.tcx, data);
755+
let implicit_bounds = object_region_bounds(self.tcx, data);
750756

751757
let explicit_bound = region;
752758

@@ -759,7 +765,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
759765
cause,
760766
self.recursion_depth,
761767
self.param_env,
762-
outlives.to_predicate(self.infcx.tcx),
768+
outlives.to_predicate(self.tcx),
763769
));
764770
}
765771
}

0 commit comments

Comments
 (0)