Skip to content

Commit 8278314

Browse files
committed
Remove PredicateKind::Atom
1 parent 8a65184 commit 8278314

File tree

12 files changed

+72
-100
lines changed

12 files changed

+72
-100
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
541541
span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
542542
}
543543
};
544-
let predicate =
545-
predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
544+
let predicate = predicate.rebind(atom).potentially_quantified(self.tcx);
546545

547546
Obligation::new(cause.clone(), param_env, predicate)
548547
})

compiler/rustc_infer/src/traits/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn anonymize_predicate<'tcx>(
1414
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
1515
tcx.reuse_or_mk_predicate(pred, new)
1616
}
17-
ty::PredicateKind::Atom(_) => pred,
1817
}
1918
}
2019

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ impl FlagComputation {
211211
computation.add_predicate_atom(atom)
212212
});
213213
}
214-
ty::PredicateKind::Atom(atom) => self.add_predicate_atom(atom),
215214
}
216215
}
217216

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ crate struct PredicateInner<'tcx> {
10371037
}
10381038

10391039
#[cfg(target_arch = "x86_64")]
1040-
static_assert_size!(PredicateInner<'_>, 48);
1040+
static_assert_size!(PredicateInner<'_>, 40);
10411041

10421042
#[derive(Clone, Copy, Lift)]
10431043
pub struct Predicate<'tcx> {
@@ -1074,10 +1074,6 @@ impl<'tcx> Predicate<'tcx> {
10741074
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
10751075
match self.kind() {
10761076
&PredicateKind::ForAll(binder) => binder.skip_binder(),
1077-
&PredicateKind::Atom(atom) => {
1078-
debug_assert!(!atom.has_escaping_bound_vars());
1079-
atom
1080-
}
10811077
}
10821078
}
10831079

@@ -1090,7 +1086,6 @@ impl<'tcx> Predicate<'tcx> {
10901086
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
10911087
match self.kind() {
10921088
&PredicateKind::ForAll(binder) => binder.skip_binder(),
1093-
&PredicateKind::Atom(atom) => atom,
10941089
}
10951090
}
10961091

@@ -1099,19 +1094,14 @@ impl<'tcx> Predicate<'tcx> {
10991094
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
11001095
match self.kind() {
11011096
&PredicateKind::ForAll(binder) => binder,
1102-
&PredicateKind::Atom(atom) => {
1103-
debug_assert!(!atom.has_escaping_bound_vars());
1104-
Binder::dummy(atom)
1105-
}
11061097
}
11071098
}
11081099

11091100
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
11101101
/// contained unbound variables by shifting these variables outwards.
1111-
pub fn bound_atom_with_opt_escaping(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1102+
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
11121103
match self.kind() {
11131104
&PredicateKind::ForAll(binder) => binder,
1114-
&PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
11151105
}
11161106
}
11171107
}
@@ -1136,7 +1126,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
11361126
pub enum PredicateKind<'tcx> {
11371127
/// `for<'a>: ...`
11381128
ForAll(Binder<PredicateAtom<'tcx>>),
1139-
Atom(PredicateAtom<'tcx>),
11401129
}
11411130

11421131
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@@ -1189,16 +1178,8 @@ pub enum PredicateAtom<'tcx> {
11891178

11901179
impl<'tcx> Binder<PredicateAtom<'tcx>> {
11911180
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
1192-
pub fn potentially_quantified(
1193-
self,
1194-
tcx: TyCtxt<'tcx>,
1195-
qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
1196-
) -> Predicate<'tcx> {
1197-
match self.no_bound_vars() {
1198-
Some(atom) => PredicateKind::Atom(atom),
1199-
None => qualifier(self),
1200-
}
1201-
.to_predicate(tcx)
1181+
pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1182+
PredicateKind::ForAll(self).to_predicate(tcx)
12021183
}
12031184
}
12041185

@@ -1289,11 +1270,7 @@ impl<'tcx> Predicate<'tcx> {
12891270
let substs = trait_ref.skip_binder().substs;
12901271
let pred = self.skip_binders();
12911272
let new = pred.subst(tcx, substs);
1292-
if new != pred {
1293-
ty::Binder::bind(new).potentially_quantified(tcx, PredicateKind::ForAll)
1294-
} else {
1295-
self
1296-
}
1273+
if new != pred { ty::Binder::bind(new).potentially_quantified(tcx) } else { self }
12971274
}
12981275
}
12991276

@@ -1425,7 +1402,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
14251402
#[inline(always)]
14261403
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
14271404
debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self);
1428-
tcx.mk_predicate(PredicateKind::Atom(self))
1405+
tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self)))
14291406
}
14301407
}
14311408

@@ -1450,27 +1427,25 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
14501427
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
14511428
self.value
14521429
.map_bound(|value| PredicateAtom::Trait(value, self.constness))
1453-
.potentially_quantified(tcx, PredicateKind::ForAll)
1430+
.potentially_quantified(tcx)
14541431
}
14551432
}
14561433

14571434
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
14581435
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1459-
self.map_bound(PredicateAtom::RegionOutlives)
1460-
.potentially_quantified(tcx, PredicateKind::ForAll)
1436+
self.map_bound(PredicateAtom::RegionOutlives).potentially_quantified(tcx)
14611437
}
14621438
}
14631439

14641440
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
14651441
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1466-
self.map_bound(PredicateAtom::TypeOutlives)
1467-
.potentially_quantified(tcx, PredicateKind::ForAll)
1442+
self.map_bound(PredicateAtom::TypeOutlives).potentially_quantified(tcx)
14681443
}
14691444
}
14701445

14711446
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14721447
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1473-
self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll)
1448+
self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx)
14741449
}
14751450
}
14761451

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,6 @@ define_print_and_forward_display! {
20692069

20702070
ty::Predicate<'tcx> {
20712071
match self.kind() {
2072-
&ty::PredicateKind::Atom(atom) => p!(print(atom)),
20732072
ty::PredicateKind::ForAll(binder) => p!(print(binder)),
20742073
}
20752074
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
232232
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
233233
match *self {
234234
ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
235-
ty::PredicateKind::Atom(atom) => write!(f, "{:?}", atom),
236235
}
237236
}
238237
}
@@ -486,7 +485,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
486485
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
487486
match self {
488487
ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll),
489-
ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom),
490488
}
491489
}
492490
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -346,45 +346,47 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
346346
let infcx = self.selcx.infcx();
347347

348348
match *obligation.predicate.kind() {
349-
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
350-
// Evaluation will discard candidates using the leak check.
351-
// This means we need to pass it the bound version of our
352-
// predicate.
353-
ty::PredicateAtom::Trait(trait_ref, _constness) => {
354-
let trait_obligation = obligation.with(binder.rebind(trait_ref));
355-
356-
self.process_trait_obligation(
357-
obligation,
358-
trait_obligation,
359-
&mut pending_obligation.stalled_on,
360-
)
361-
}
362-
ty::PredicateAtom::Projection(data) => {
363-
let project_obligation = obligation.with(binder.rebind(data));
349+
ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => {
350+
match binder.skip_binder() {
351+
// Evaluation will discard candidates using the leak check.
352+
// This means we need to pass it the bound version of our
353+
// predicate.
354+
ty::PredicateAtom::Trait(trait_ref, _constness) => {
355+
let trait_obligation = obligation.with(binder.rebind(trait_ref));
356+
357+
self.process_trait_obligation(
358+
obligation,
359+
trait_obligation,
360+
&mut pending_obligation.stalled_on,
361+
)
362+
}
363+
ty::PredicateAtom::Projection(data) => {
364+
let project_obligation = obligation.with(binder.rebind(data));
364365

365-
self.process_projection_obligation(
366-
project_obligation,
367-
&mut pending_obligation.stalled_on,
368-
)
369-
}
370-
ty::PredicateAtom::RegionOutlives(_)
371-
| ty::PredicateAtom::TypeOutlives(_)
372-
| ty::PredicateAtom::WellFormed(_)
373-
| ty::PredicateAtom::ObjectSafe(_)
374-
| ty::PredicateAtom::ClosureKind(..)
375-
| ty::PredicateAtom::Subtype(_)
376-
| ty::PredicateAtom::ConstEvaluatable(..)
377-
| ty::PredicateAtom::ConstEquate(..) => {
378-
let pred = infcx.replace_bound_vars_with_placeholders(binder);
379-
ProcessResult::Changed(mk_pending(vec![
380-
obligation.with(pred.to_predicate(self.selcx.tcx())),
381-
]))
382-
}
383-
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
384-
bug!("TypeWellFormedFromEnv is only used for Chalk")
366+
self.process_projection_obligation(
367+
project_obligation,
368+
&mut pending_obligation.stalled_on,
369+
)
370+
}
371+
ty::PredicateAtom::RegionOutlives(_)
372+
| ty::PredicateAtom::TypeOutlives(_)
373+
| ty::PredicateAtom::WellFormed(_)
374+
| ty::PredicateAtom::ObjectSafe(_)
375+
| ty::PredicateAtom::ClosureKind(..)
376+
| ty::PredicateAtom::Subtype(_)
377+
| ty::PredicateAtom::ConstEvaluatable(..)
378+
| ty::PredicateAtom::ConstEquate(..) => {
379+
let pred = infcx.replace_bound_vars_with_placeholders(binder);
380+
ProcessResult::Changed(mk_pending(vec![
381+
obligation.with(pred.to_predicate(self.selcx.tcx())),
382+
]))
383+
}
384+
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
385+
bug!("TypeWellFormedFromEnv is only used for Chalk")
386+
}
385387
}
386-
},
387-
ty::PredicateKind::Atom(atom) => match atom {
388+
}
389+
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
388390
ty::PredicateAtom::Trait(data, _) => {
389391
let trait_obligation = obligation.with(Binder::dummy(data));
390392

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ fn compute_implied_outlives_bounds<'tcx>(
9595
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
9696
assert!(!obligation.has_escaping_bound_vars());
9797
match obligation.predicate.kind() {
98-
&ty::PredicateKind::ForAll(..) => vec![],
99-
&ty::PredicateKind::Atom(atom) => match atom {
98+
&ty::PredicateKind::ForAll(binder)
99+
if binder.skip_binder().has_escaping_bound_vars() =>
100+
{
101+
vec![]
102+
}
103+
&ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
100104
ty::PredicateAtom::Trait(..)
101105
| ty::PredicateAtom::Subtype(..)
102106
| ty::PredicateAtom::Projection(..)

compiler/rustc_typeck/src/collect.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,10 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19491949
let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
19501950
ty::OutlivesPredicate(ty, re_root_empty),
19511951
));
1952-
predicates.insert((
1953-
predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll),
1954-
span,
1955-
));
1952+
predicates.insert((predicate.potentially_quantified(tcx), span));
19561953
}
19571954
}
19581955

@@ -1996,7 +1993,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19961993
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
19971994
ty::OutlivesPredicate(ty, region),
19981995
))
1999-
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
1996+
.potentially_quantified(tcx),
20001997
lifetime.span,
20011998
));
20021999
}

compiler/rustc_typeck/src/outlives/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
3131
let mut pred: Vec<String> = predicates
3232
.iter()
3333
.map(|(out_pred, _)| match out_pred.kind() {
34-
ty::PredicateKind::Atom(ty::PredicateAtom::RegionOutlives(p)) => {
35-
p.to_string()
36-
}
37-
ty::PredicateKind::Atom(ty::PredicateAtom::TypeOutlives(p)) => {
38-
p.to_string()
39-
}
40-
err => bug!("unexpected predicate {:?}", err),
34+
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
35+
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
36+
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
37+
err => bug!("unexpected predicate {:?}", err),
38+
},
4139
})
4240
.collect();
4341
pred.sort();

src/test/ui/specialization/min_specialization/repeated_projection_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))`
1+
error: cannot specialize on `ForAll(Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))))`
22
--> $DIR/repeated_projection_type.rs:19:1
33
|
44
LL | / impl<I, V: Id<This = (I,)>> X for V {

src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
115115
.filter(|p| !p.is_global())
116116
.filter_map(|obligation| {
117117
// Note that we do not want to deal with qualified predicates here.
118-
if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
119-
if pred.def_id() == sized_trait {
120-
return None;
118+
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
119+
match binder.skip_binder() {
120+
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
121+
if pred.def_id() == sized_trait {
122+
return None;
123+
}
124+
Some(pred)
121125
}
122-
Some(pred)
123-
} else {
124-
None
126+
_ => None,
125127
}
126128
})
127129
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)