Skip to content

Commit 9852b42

Browse files
committed
PredicateKint -> PredicateKind, the beginning of the end
1 parent 506f430 commit 9852b42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+742
-740
lines changed

src/librustc_infer/infer/canonical/query_response.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
531531
GenericArg<'tcx>,
532532
ty::Region<'tcx>,
533533
>| match k1.unpack() {
534-
GenericArgKind::Lifetime(r1) => self.tcx.intern_predicate_kint(
535-
ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
536-
),
537-
GenericArgKind::Type(t1) => self.tcx.intern_predicate_kint(
538-
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(t1, r2)),
539-
),
534+
GenericArgKind::Lifetime(r1) => {
535+
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
536+
.to_predicate(self.tcx)
537+
}
538+
GenericArgKind::Type(t1) => {
539+
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
540+
.to_predicate(self.tcx)
541+
}
540542
GenericArgKind::Const(..) => {
541543
// Consts cannot outlive one another, so we don't expect to
542544
// ecounter this branch.
@@ -545,9 +547,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
545547
};
546548

547549
let predicate = if let Some(constraint) = constraint.no_bound_vars() {
548-
to_predicate(constraint).to_predicate(self.tcx)
550+
to_predicate(constraint)
549551
} else {
550-
ty::PredicateKint::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
552+
ty::PredicateKind::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
551553
};
552554

553555
Obligation::new(cause.clone(), param_env, predicate)
@@ -670,7 +672,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
670672
self.obligations.push(Obligation {
671673
cause: self.cause.clone(),
672674
param_env: self.param_env,
673-
predicate: ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(sup, sub))
675+
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
674676
.to_predicate(self.infcx.tcx),
675677
recursion_depth: 0,
676678
});

src/librustc_infer/infer/combine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
308308
self.obligations.push(Obligation::new(
309309
self.trace.cause.clone(),
310310
self.param_env,
311-
ty::PredicateKint::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
311+
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
312312
));
313313
}
314314

@@ -400,9 +400,9 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
400400
b: &'tcx ty::Const<'tcx>,
401401
) {
402402
let predicate = if a_is_expected {
403-
ty::PredicateKint::ConstEquate(a, b)
403+
ty::PredicateKind::ConstEquate(a, b)
404404
} else {
405-
ty::PredicateKint::ConstEquate(b, a)
405+
ty::PredicateKind::ConstEquate(b, a)
406406
};
407407
self.obligations.push(Obligation::new(
408408
self.trace.cause.clone(),

src/librustc_infer/infer/outlives/env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::infer::{GenericKind, InferCtxt};
33
use crate::traits::query::OutlivesBound;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_hir as hir;
6-
use rustc_middle::ty;
6+
use rustc_middle::ty::{self, TyCtxt};
77

88
use super::explicit_outlives_bounds;
99

@@ -69,15 +69,15 @@ pub struct OutlivesEnvironment<'tcx> {
6969
pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;
7070

7171
impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
72-
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
72+
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
7373
let mut env = OutlivesEnvironment {
7474
param_env,
7575
free_region_map: Default::default(),
7676
region_bound_pairs_map: Default::default(),
7777
region_bound_pairs_accum: vec![],
7878
};
7979

80-
env.add_outlives_bounds(None, explicit_outlives_bounds(param_env));
80+
env.add_outlives_bounds(None, explicit_outlives_bounds(tcx, param_env));
8181

8282
env
8383
}

src/librustc_infer/infer/outlives/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ pub mod obligations;
55
pub mod verify;
66

77
use rustc_middle::traits::query::OutlivesBound;
8-
use rustc_middle::ty;
8+
use rustc_middle::ty::{self, TyCtxt};
99

1010
pub fn explicit_outlives_bounds<'tcx>(
11+
tcx: TyCtxt<'tcx>,
1112
param_env: ty::ParamEnv<'tcx>,
1213
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1314
debug!("explicit_outlives_bounds()");

src/librustc_infer/infer/outlives/verify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
331331
compare_ty: impl Fn(Ty<'tcx>) -> bool,
332332
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
333333
) -> impl Iterator<Item = ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
334+
let tcx = self.tcx;
334335
predicates
335-
.filter_map(|p| p.to_opt_type_outlives())
336+
.filter_map(move |p| p.to_opt_type_outlives(tcx))
336337
.filter_map(|p| p.no_bound_vars())
337338
.filter(move |p| compare_ty(p.0))
338339
}

src/librustc_infer/infer/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
100100
self.fields.obligations.push(Obligation::new(
101101
self.fields.trace.cause.clone(),
102102
self.fields.param_env,
103-
ty::PredicateKint::Subtype(ty::SubtypePredicate {
103+
ty::PredicateKind::Subtype(ty::SubtypePredicate {
104104
a_is_expected: self.a_is_expected,
105105
a,
106106
b,

src/librustc_infer/traits/util.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
1111
pred: ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
13-
let kind = pred.kint(tcx);
13+
let kind = pred.kind();
1414
let new = match kind {
15-
ty::PredicateKint::ForAll(binder) => {
16-
ty::PredicateKint::ForAll(tcx.anonymize_late_bound_regions(binder))
15+
ty::PredicateKind::ForAll(binder) => {
16+
ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder))
1717
}
18-
&ty::PredicateKint::Trait(data, constness) => ty::PredicateKint::Trait(data, constness),
18+
&ty::PredicateKind::Trait(data, constness) => ty::PredicateKind::Trait(data, constness),
1919

20-
&ty::PredicateKint::RegionOutlives(data) => ty::PredicateKint::RegionOutlives(data),
20+
&ty::PredicateKind::RegionOutlives(data) => ty::PredicateKind::RegionOutlives(data),
2121

22-
&ty::PredicateKint::TypeOutlives(data) => ty::PredicateKint::TypeOutlives(data),
22+
&ty::PredicateKind::TypeOutlives(data) => ty::PredicateKind::TypeOutlives(data),
2323

24-
&ty::PredicateKint::Projection(data) => ty::PredicateKint::Projection(data),
24+
&ty::PredicateKind::Projection(data) => ty::PredicateKind::Projection(data),
2525

26-
&ty::PredicateKint::WellFormed(data) => ty::PredicateKint::WellFormed(data),
26+
&ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
2727

28-
&ty::PredicateKint::ObjectSafe(data) => ty::PredicateKint::ObjectSafe(data),
28+
&ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
2929

30-
&ty::PredicateKint::ClosureKind(closure_def_id, closure_substs, kind) => {
31-
ty::PredicateKint::ClosureKind(closure_def_id, closure_substs, kind)
30+
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
31+
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
3232
}
3333

34-
&ty::PredicateKint::Subtype(data) => ty::PredicateKint::Subtype(data),
34+
&ty::PredicateKind::Subtype(data) => ty::PredicateKind::Subtype(data),
3535

36-
&ty::PredicateKint::ConstEvaluatable(def_id, substs) => {
37-
ty::PredicateKint::ConstEvaluatable(def_id, substs)
36+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
37+
ty::PredicateKind::ConstEvaluatable(def_id, substs)
3838
}
3939

40-
&ty::PredicateKint::ConstEquate(c1, c2) => ty::PredicateKint::ConstEquate(c1, c2),
40+
&ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
4141
};
4242

4343
if new != *kind { new.to_predicate(tcx) } else { pred }
@@ -145,22 +145,22 @@ fn predicate_obligation<'tcx>(
145145
}
146146

147147
impl Elaborator<'tcx> {
148-
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
149-
FilterToTraits::new(self)
148+
pub fn filter_to_traits(self) -> FilterToTraits<'tcx, Self> {
149+
FilterToTraits::new(self.visited.tcx, self)
150150
}
151151

152152
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
153153
let tcx = self.visited.tcx;
154-
let pred = match obligation.predicate.kint(tcx) {
155-
// We have to be careful and rebind this whenever
154+
let pred = match obligation.predicate.kind() {
155+
// We have to be careful and rebind this when
156156
// dealing with a predicate further down.
157-
ty::PredicateKint::ForAll(binder) => binder.skip_binder(),
157+
ty::PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
158158
pred => pred,
159159
};
160160

161161
match pred {
162-
ty::PredicateKint::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
163-
ty::PredicateKint::Trait(ref data, _) => {
162+
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
163+
ty::PredicateKind::Trait(data, _) => {
164164
// Get predicates declared on the trait.
165165
let predicates = tcx.super_predicates_of(data.def_id());
166166

@@ -181,36 +181,36 @@ impl Elaborator<'tcx> {
181181

182182
self.stack.extend(obligations);
183183
}
184-
ty::PredicateKint::WellFormed(..) => {
184+
ty::PredicateKind::WellFormed(..) => {
185185
// Currently, we do not elaborate WF predicates,
186186
// although we easily could.
187187
}
188-
ty::PredicateKint::ObjectSafe(..) => {
188+
ty::PredicateKind::ObjectSafe(..) => {
189189
// Currently, we do not elaborate object-safe
190190
// predicates.
191191
}
192-
ty::PredicateKint::Subtype(..) => {
192+
ty::PredicateKind::Subtype(..) => {
193193
// Currently, we do not "elaborate" predicates like `X <: Y`,
194194
// though conceivably we might.
195195
}
196-
ty::PredicateKint::Projection(..) => {
196+
ty::PredicateKind::Projection(..) => {
197197
// Nothing to elaborate in a projection predicate.
198198
}
199-
ty::PredicateKint::ClosureKind(..) => {
199+
ty::PredicateKind::ClosureKind(..) => {
200200
// Nothing to elaborate when waiting for a closure's kind to be inferred.
201201
}
202-
ty::PredicateKint::ConstEvaluatable(..) => {
202+
ty::PredicateKind::ConstEvaluatable(..) => {
203203
// Currently, we do not elaborate const-evaluatable
204204
// predicates.
205205
}
206-
ty::PredicateKint::ConstEquate(..) => {
206+
ty::PredicateKind::ConstEquate(..) => {
207207
// Currently, we do not elaborate const-equate
208208
// predicates.
209209
}
210-
ty::PredicateKint::RegionOutlives(..) => {
210+
ty::PredicateKind::RegionOutlives(..) => {
211211
// Nothing to elaborate from `'a: 'b`.
212212
}
213-
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
213+
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
214214
// We know that `T: 'a` for some type `T`. We can
215215
// often elaborate this. For example, if we know that
216216
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -240,15 +240,15 @@ impl Elaborator<'tcx> {
240240
if r.is_late_bound() {
241241
None
242242
} else {
243-
Some(ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(
243+
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
244244
r, r_min,
245245
)))
246246
}
247247
}
248248

249249
Component::Param(p) => {
250250
let ty = tcx.mk_ty_param(p.index, p.name);
251-
Some(ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(
251+
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
252252
ty, r_min,
253253
)))
254254
}
@@ -293,7 +293,7 @@ impl Iterator for Elaborator<'tcx> {
293293
// Supertrait iterator
294294
///////////////////////////////////////////////////////////////////////////
295295

296-
pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
296+
pub type Supertraits<'tcx> = FilterToTraits<'tcx, Elaborator<'tcx>>;
297297

298298
pub fn supertraits<'tcx>(
299299
tcx: TyCtxt<'tcx>,
@@ -315,22 +315,23 @@ pub fn transitive_bounds<'tcx>(
315315

316316
/// A filter around an iterator of predicates that makes it yield up
317317
/// just trait references.
318-
pub struct FilterToTraits<I> {
318+
pub struct FilterToTraits<'tcx, I> {
319+
tcx: TyCtxt<'tcx>,
319320
base_iterator: I,
320321
}
321322

322-
impl<I> FilterToTraits<I> {
323-
fn new(base: I) -> FilterToTraits<I> {
324-
FilterToTraits { base_iterator: base }
323+
impl<'tcx, I> FilterToTraits<'tcx, I> {
324+
fn new(tcx: TyCtxt<'tcx>, base: I) -> FilterToTraits<'tcx, I> {
325+
FilterToTraits { tcx, base_iterator: base }
325326
}
326327
}
327328

328-
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
329+
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<'tcx, I> {
329330
type Item = ty::PolyTraitRef<'tcx>;
330331

331332
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
332333
while let Some(obligation) = self.base_iterator.next() {
333-
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
334+
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref(self.tcx) {
334335
return Some(data);
335336
}
336337
}

0 commit comments

Comments
 (0)