Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d8cf8ba

Browse files
committed
introduce PredicateAtom
1 parent 52af82b commit d8cf8ba

File tree

54 files changed

+795
-842
lines changed

Some content is hidden

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

54 files changed

+795
-842
lines changed

src/librustc_infer/infer/canonical/query_response.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
530530

531531
let predicate = match k1.unpack() {
532532
GenericArgKind::Lifetime(r1) => {
533-
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
533+
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
534534
.to_predicate(self.tcx)
535535
}
536536
GenericArgKind::Type(t1) => {
537-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
537+
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
538538
.to_predicate(self.tcx)
539539
}
540540
GenericArgKind::Const(..) => {
@@ -665,7 +665,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
665665
self.obligations.push(Obligation {
666666
cause: self.cause.clone(),
667667
param_env: self.param_env,
668-
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
668+
predicate: ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(sup, sub))
669669
.to_predicate(self.infcx.tcx),
670670
recursion_depth: 0,
671671
});

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::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
311+
ty::PredicateAtom::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::PredicateKind::ConstEquate(a, b)
403+
ty::PredicateAtom::ConstEquate(a, b)
404404
} else {
405-
ty::PredicateKind::ConstEquate(b, a)
405+
ty::PredicateAtom::ConstEquate(b, a)
406406
};
407407
self.obligations.push(Obligation::new(
408408
self.trace.cause.clone(),

src/librustc_infer/infer/outlives/mod.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ pub mod verify;
66

77
use rustc_middle::traits::query::OutlivesBound;
88
use rustc_middle::ty;
9+
use rustc_middle::ty::fold::TypeFoldable;
910

1011
pub fn explicit_outlives_bounds<'tcx>(
1112
param_env: ty::ParamEnv<'tcx>,
1213
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1314
debug!("explicit_outlives_bounds()");
14-
param_env.caller_bounds().into_iter().filter_map(move |predicate| match predicate.kind() {
15-
ty::PredicateKind::Projection(..)
16-
| ty::PredicateKind::Trait(..)
17-
| ty::PredicateKind::Subtype(..)
18-
| ty::PredicateKind::WellFormed(..)
19-
| ty::PredicateKind::ObjectSafe(..)
20-
| ty::PredicateKind::ClosureKind(..)
21-
| ty::PredicateKind::TypeOutlives(..)
22-
| ty::PredicateKind::ConstEvaluatable(..)
23-
| ty::PredicateKind::ConstEquate(..) => None,
24-
ty::PredicateKind::RegionOutlives(ref data) => data
25-
.no_bound_vars()
26-
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
27-
})
15+
param_env
16+
.caller_bounds()
17+
.into_iter()
18+
.map(ty::Predicate::skip_binders)
19+
.filter(TypeFoldable::has_escaping_bound_vars)
20+
.filter_map(move |atom| match atom {
21+
ty::PredicateAtom::Projection(..)
22+
| ty::PredicateAtom::Trait(..)
23+
| ty::PredicateAtom::Subtype(..)
24+
| ty::PredicateAtom::WellFormed(..)
25+
| ty::PredicateAtom::ObjectSafe(..)
26+
| ty::PredicateAtom::ClosureKind(..)
27+
| ty::PredicateAtom::TypeOutlives(..)
28+
| ty::PredicateAtom::ConstEvaluatable(..)
29+
| ty::PredicateAtom::ConstEquate(..) => None,
30+
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
31+
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
32+
}
33+
})
2834
}

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::PredicateKind::Subtype(ty::SubtypePredicate {
103+
ty::PredicateAtom::Subtype(ty::SubtypePredicate {
104104
a_is_expected: self.a_is_expected,
105105
a,
106106
b,

src/librustc_infer/traits/util.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@ pub fn anonymize_predicate<'tcx>(
1515
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
1616
tcx.reuse_or_mk_predicate(pred, new)
1717
}
18-
ty::PredicateKind::Trait(_, _)
19-
| ty::PredicateKind::RegionOutlives(_)
20-
| ty::PredicateKind::TypeOutlives(_)
21-
| ty::PredicateKind::Projection(_)
22-
| ty::PredicateKind::WellFormed(_)
23-
| ty::PredicateKind::ObjectSafe(_)
24-
| ty::PredicateKind::ClosureKind(_, _, _)
25-
| ty::PredicateKind::Subtype(_)
26-
| ty::PredicateKind::ConstEvaluatable(_, _)
27-
| ty::PredicateKind::ConstEquate(_, _) => pred,
18+
ty::PredicateKind::Atom(_) => pred,
2819
}
2920
}
3021

@@ -137,11 +128,8 @@ impl Elaborator<'tcx> {
137128
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
138129
let tcx = self.visited.tcx;
139130

140-
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
141-
ty::PredicateKind::ForAll(_) => {
142-
bug!("unexpected predicate: {:?}", obligation.predicate)
143-
}
144-
ty::PredicateKind::Trait(data, _) => {
131+
match obligation.predicate.skip_binders() {
132+
ty::PredicateAtom::Trait(data, _) => {
145133
// Get predicates declared on the trait.
146134
let predicates = tcx.super_predicates_of(data.def_id());
147135

@@ -162,36 +150,36 @@ impl Elaborator<'tcx> {
162150

163151
self.stack.extend(obligations);
164152
}
165-
ty::PredicateKind::WellFormed(..) => {
153+
ty::PredicateAtom::WellFormed(..) => {
166154
// Currently, we do not elaborate WF predicates,
167155
// although we easily could.
168156
}
169-
ty::PredicateKind::ObjectSafe(..) => {
157+
ty::PredicateAtom::ObjectSafe(..) => {
170158
// Currently, we do not elaborate object-safe
171159
// predicates.
172160
}
173-
ty::PredicateKind::Subtype(..) => {
161+
ty::PredicateAtom::Subtype(..) => {
174162
// Currently, we do not "elaborate" predicates like `X <: Y`,
175163
// though conceivably we might.
176164
}
177-
ty::PredicateKind::Projection(..) => {
165+
ty::PredicateAtom::Projection(..) => {
178166
// Nothing to elaborate in a projection predicate.
179167
}
180-
ty::PredicateKind::ClosureKind(..) => {
168+
ty::PredicateAtom::ClosureKind(..) => {
181169
// Nothing to elaborate when waiting for a closure's kind to be inferred.
182170
}
183-
ty::PredicateKind::ConstEvaluatable(..) => {
171+
ty::PredicateAtom::ConstEvaluatable(..) => {
184172
// Currently, we do not elaborate const-evaluatable
185173
// predicates.
186174
}
187-
ty::PredicateKind::ConstEquate(..) => {
175+
ty::PredicateAtom::ConstEquate(..) => {
188176
// Currently, we do not elaborate const-equate
189177
// predicates.
190178
}
191-
ty::PredicateKind::RegionOutlives(..) => {
179+
ty::PredicateAtom::RegionOutlives(..) => {
192180
// Nothing to elaborate from `'a: 'b`.
193181
}
194-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
182+
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
195183
// We know that `T: 'a` for some type `T`. We can
196184
// often elaborate this. For example, if we know that
197185
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -221,15 +209,15 @@ impl Elaborator<'tcx> {
221209
if r.is_late_bound() {
222210
None
223211
} else {
224-
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
212+
Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
225213
r, r_min,
226214
)))
227215
}
228216
}
229217

230218
Component::Param(p) => {
231219
let ty = tcx.mk_ty_param(p.index, p.name);
232-
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
220+
Some(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
233221
ty, r_min,
234222
)))
235223
}

src/librustc_lint/builtin.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,15 +1202,15 @@ declare_lint_pass!(
12021202
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
12031203
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
12041204
use rustc_middle::ty::fold::TypeFoldable;
1205-
use rustc_middle::ty::PredicateKind::*;
1205+
use rustc_middle::ty::PredicateAtom::*;
12061206

12071207
if cx.tcx.features().trivial_bounds {
12081208
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
12091209
let predicates = cx.tcx.predicates_of(def_id);
12101210
for &(predicate, span) in predicates.predicates {
12111211
// We don't actually look inside of the predicate,
12121212
// so it is safe to skip this binder here.
1213-
let predicate_kind_name = match predicate.ignore_quantifiers().skip_binder().kind() {
1213+
let predicate_kind_name = match predicate.skip_binders() {
12141214
Trait(..) => "Trait",
12151215
TypeOutlives(..) |
12161216
RegionOutlives(..) => "Lifetime",
@@ -1225,7 +1225,6 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
12251225
Subtype(..) |
12261226
ConstEvaluatable(..) |
12271227
ConstEquate(..) => continue,
1228-
ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
12291228
};
12301229
if predicate.is_global() {
12311230
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {
@@ -1500,8 +1499,8 @@ impl ExplicitOutlivesRequirements {
15001499
) -> Vec<ty::Region<'tcx>> {
15011500
inferred_outlives
15021501
.iter()
1503-
.filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
1504-
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
1502+
.filter_map(|(pred, _)| match pred.skip_binders() {
1503+
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
15051504
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
15061505
_ => None,
15071506
},
@@ -1516,8 +1515,8 @@ impl ExplicitOutlivesRequirements {
15161515
) -> Vec<ty::Region<'tcx>> {
15171516
inferred_outlives
15181517
.iter()
1519-
.filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
1520-
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
1518+
.filter_map(|(pred, _)| match pred.skip_binders() {
1519+
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
15211520
a.is_param(index).then_some(b)
15221521
}
15231522
_ => None,

src/librustc_lint/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
147147
let mut has_emitted = false;
148148
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
149149
// We only look at the `DefId`, so it is safe to skip the binder here.
150-
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
151-
predicate.ignore_quantifiers().skip_binder().kind()
150+
if let ty::PredicateAtom::Trait(ref poly_trait_predicate, _) =
151+
predicate.skip_binders()
152152
{
153153
let def_id = poly_trait_predicate.trait_ref.def_id;
154154
let descr_pre =

src/librustc_middle/ty/flags.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -208,46 +208,48 @@ impl FlagComputation {
208208

209209
fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
210210
match kind {
211-
ty::PredicateKind::Trait(trait_pred, _constness) => {
212-
self.add_substs(trait_pred.trait_ref.substs);
213-
}
214-
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
215-
self.add_region(a);
216-
self.add_region(b);
217-
}
218-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
219-
self.add_ty(ty);
220-
self.add_region(region);
221-
}
222-
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
223-
self.add_ty(a);
224-
self.add_ty(b);
225-
}
226-
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
227-
self.add_projection_ty(projection_ty);
228-
self.add_ty(ty);
229-
}
230-
ty::PredicateKind::WellFormed(arg) => {
231-
self.add_substs(slice::from_ref(arg));
232-
}
233-
ty::PredicateKind::ObjectSafe(_def_id) => {}
234-
ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
235-
self.add_substs(substs);
236-
}
237-
ty::PredicateKind::ConstEvaluatable(_def_id, substs) => {
238-
self.add_substs(substs);
239-
}
240-
ty::PredicateKind::ConstEquate(expected, found) => {
241-
self.add_const(expected);
242-
self.add_const(found);
243-
}
244211
ty::PredicateKind::ForAll(binder) => {
245212
let mut computation = FlagComputation::new();
246213

247214
computation.add_predicate(binder.skip_binder());
248215

249216
self.add_bound_computation(computation);
250217
}
218+
&ty::PredicateKind::Atom(atom) => match atom {
219+
ty::PredicateAtom::Trait(trait_pred, _constness) => {
220+
self.add_substs(trait_pred.trait_ref.substs);
221+
}
222+
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
223+
self.add_region(a);
224+
self.add_region(b);
225+
}
226+
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
227+
self.add_ty(ty);
228+
self.add_region(region);
229+
}
230+
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
231+
self.add_ty(a);
232+
self.add_ty(b);
233+
}
234+
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
235+
self.add_projection_ty(projection_ty);
236+
self.add_ty(ty);
237+
}
238+
ty::PredicateAtom::WellFormed(arg) => {
239+
self.add_substs(slice::from_ref(&arg));
240+
}
241+
ty::PredicateAtom::ObjectSafe(_def_id) => {}
242+
ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
243+
self.add_substs(substs);
244+
}
245+
ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
246+
self.add_substs(substs);
247+
}
248+
ty::PredicateAtom::ConstEquate(expected, found) => {
249+
self.add_const(expected);
250+
self.add_const(found);
251+
}
252+
},
251253
}
252254
}
253255

0 commit comments

Comments
 (0)