Skip to content

Commit 4cd6f85

Browse files
committed
Remove PredicateKind
1 parent 4cb3d6f commit 4cd6f85

File tree

12 files changed

+38
-68
lines changed

12 files changed

+38
-68
lines changed

compiler/rustc_infer/src/traits/util.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ pub fn anonymize_predicate<'tcx>(
99
tcx: TyCtxt<'tcx>,
1010
pred: ty::Predicate<'tcx>,
1111
) -> ty::Predicate<'tcx> {
12-
match *pred.kind() {
13-
ty::PredicateKind::ForAll(binder) => {
14-
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
15-
tcx.reuse_or_mk_predicate(pred, new)
16-
}
17-
}
12+
let new = tcx.anonymize_late_bound_regions(pred.kind());
13+
tcx.reuse_or_mk_predicate(pred, new)
1814
}
1915

2016
struct PredicateSet<'tcx> {

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
4444
}
4545

4646
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
47-
type Variant = ty::PredicateKind<'tcx>;
47+
type Variant = ty::Binder<ty::PredicateAtom<'tcx>>;
4848
fn variant(&self) -> &Self::Variant {
49-
self.kind()
49+
self.kind_ref()
5050
}
5151
}
5252

@@ -226,9 +226,9 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
226226
assert!(pos >= SHORTHAND_OFFSET);
227227
let shorthand = pos - SHORTHAND_OFFSET;
228228

229-
decoder.with_position(shorthand, ty::PredicateKind::decode)
229+
decoder.with_position(shorthand, ty::Binder::<ty::PredicateAtom<'tcx>>::decode)
230230
} else {
231-
ty::PredicateKind::decode(decoder)
231+
ty::Binder::<ty::PredicateAtom<'tcx>>::decode(decoder)
232232
}?;
233233
let predicate = decoder.tcx().mk_predicate(predicate_kind);
234234
Ok(predicate)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use crate::ty::query::{self, TyCtxtAt};
1717
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
1818
use crate::ty::TyKind::*;
1919
use crate::ty::{
20-
self, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, DefIdTree,
21-
ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntVar,
22-
IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
20+
self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
21+
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
22+
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateAtom, PredicateInner,
2323
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
2424
TyVid, TypeAndMut, Visibility,
2525
};
@@ -133,7 +133,7 @@ impl<'tcx> CtxtInterners<'tcx> {
133133
}
134134

135135
#[inline(never)]
136-
fn intern_predicate(&self, kind: PredicateKind<'tcx>) -> &'tcx PredicateInner<'tcx> {
136+
fn intern_predicate(&self, kind: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
137137
self.predicate
138138
.intern(kind, |kind| {
139139
let flags = super::flags::FlagComputation::for_predicate(kind);
@@ -1948,8 +1948,8 @@ impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
19481948
}
19491949
}
19501950

1951-
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateInner<'tcx>> {
1952-
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
1951+
impl<'tcx> Borrow<Binder<PredicateAtom<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
1952+
fn borrow<'a>(&'a self) -> &'a Binder<PredicateAtom<'tcx>> {
19531953
&self.0.kind
19541954
}
19551955
}
@@ -1987,12 +1987,6 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
19871987
}
19881988
}
19891989

1990-
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
1991-
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
1992-
&self.0
1993-
}
1994-
}
1995-
19961990
macro_rules! direct_interners {
19971991
($($name:ident: $method:ident($ty:ty),)+) => {
19981992
$(impl<'tcx> PartialEq for Interned<'tcx, $ty> {
@@ -2091,7 +2085,7 @@ impl<'tcx> TyCtxt<'tcx> {
20912085
}
20922086

20932087
#[inline]
2094-
pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
2088+
pub fn mk_predicate(self, kind: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
20952089
let inner = self.interners.intern_predicate(kind);
20962090
Predicate { inner }
20972091
}
@@ -2100,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> {
21002094
pub fn reuse_or_mk_predicate(
21012095
self,
21022096
pred: Predicate<'tcx>,
2103-
kind: PredicateKind<'tcx>,
2097+
kind: Binder<PredicateAtom<'tcx>>,
21042098
) -> Predicate<'tcx> {
2105-
if *pred.kind() != kind { self.mk_predicate(kind) } else { pred }
2099+
if pred.kind() != kind { self.mk_predicate(kind) } else { pred }
21062100
}
21072101

21082102
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl FlagComputation {
2222
result
2323
}
2424

25-
pub fn for_predicate(kind: ty::PredicateKind<'_>) -> FlagComputation {
25+
pub fn for_predicate(kind: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
2626
let mut result = FlagComputation::new();
2727
result.add_predicate_kind(kind);
2828
result
@@ -204,8 +204,7 @@ impl FlagComputation {
204204
}
205205
}
206206

207-
fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
208-
let ty::PredicateKind::ForAll(binder) = kind;
207+
fn add_predicate_kind(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
209208
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
210209
}
211210

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> {
10301030

10311031
#[derive(Debug)]
10321032
crate struct PredicateInner<'tcx> {
1033-
kind: PredicateKind<'tcx>,
1033+
kind: Binder<PredicateAtom<'tcx>>,
10341034
flags: TypeFlags,
10351035
/// See the comment for the corresponding field of [TyS].
10361036
outer_exclusive_binder: ty::DebruijnIndex,
@@ -1061,7 +1061,12 @@ impl<'tcx> Eq for Predicate<'tcx> {}
10611061

10621062
impl<'tcx> Predicate<'tcx> {
10631063
#[inline(always)]
1064-
pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
1064+
pub fn kind(self) -> Binder<PredicateAtom<'tcx>> {
1065+
self.inner.kind
1066+
}
1067+
1068+
#[inline(always)]
1069+
pub fn kind_ref(&self) -> &Binder<PredicateAtom<'tcx>> {
10651070
&self.inner.kind
10661071
}
10671072

@@ -1072,7 +1077,7 @@ impl<'tcx> Predicate<'tcx> {
10721077
///
10731078
/// Note that this method panics in case this predicate has unbound variables.
10741079
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
1075-
let &PredicateKind::ForAll(binder) = self.kind();
1080+
let binder = self.kind();
10761081
binder.skip_binder()
10771082
}
10781083

@@ -1083,21 +1088,21 @@ impl<'tcx> Predicate<'tcx> {
10831088
/// Rebinding the returned atom can causes the previously bound variables
10841089
/// to end up at the wrong binding level.
10851090
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
1086-
let &PredicateKind::ForAll(binder) = self.kind();
1091+
let binder = self.kind();
10871092
binder.skip_binder()
10881093
}
10891094

10901095
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
10911096
/// `Atom`, then it is not allowed to contain escaping bound vars.
10921097
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
1093-
let &PredicateKind::ForAll(binder) = self.kind();
1098+
let binder = self.kind();
10941099
binder
10951100
}
10961101

10971102
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
10981103
/// contained unbound variables by shifting these variables outwards.
10991104
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1100-
let &PredicateKind::ForAll(binder) = self.kind();
1105+
let binder = self.kind();
11011106
binder
11021107
}
11031108
}
@@ -1117,13 +1122,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
11171122
}
11181123
}
11191124

1120-
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
1121-
#[derive(HashStable, TypeFoldable)]
1122-
pub enum PredicateKind<'tcx> {
1123-
/// `for<'a>: ...`
1124-
ForAll(Binder<PredicateAtom<'tcx>>),
1125-
}
1126-
11271125
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
11281126
#[derive(HashStable, TypeFoldable)]
11291127
pub enum PredicateAtom<'tcx> {
@@ -1175,7 +1173,7 @@ pub enum PredicateAtom<'tcx> {
11751173
impl<'tcx> Binder<PredicateAtom<'tcx>> {
11761174
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
11771175
pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1178-
PredicateKind::ForAll(self).to_predicate(tcx)
1176+
self.to_predicate(tcx)
11791177
}
11801178
}
11811179

@@ -1387,7 +1385,7 @@ pub trait ToPredicate<'tcx> {
13871385
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>;
13881386
}
13891387

1390-
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
1388+
impl ToPredicate<'tcx> for Binder<PredicateAtom<'tcx>> {
13911389
#[inline(always)]
13921390
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13931391
tcx.mk_predicate(self)
@@ -1398,7 +1396,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
13981396
#[inline(always)]
13991397
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
14001398
debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self);
1401-
tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self)))
1399+
tcx.mk_predicate(Binder::dummy(self))
14021400
}
14031401
}
14041402

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,7 @@ define_print_and_forward_display! {
20682068
}
20692069

20702070
ty::Predicate<'tcx> {
2071-
let ty::PredicateKind::ForAll(binder) = self.kind();
2071+
let binder = self.kind();
20722072
p!(print(binder))
20732073
}
20742074

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,6 @@ impl fmt::Debug for ty::Predicate<'tcx> {
228228
}
229229
}
230230

231-
impl fmt::Debug for ty::PredicateKind<'tcx> {
232-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
233-
match *self {
234-
ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
235-
}
236-
}
237-
}
238-
239231
impl fmt::Debug for ty::PredicateAtom<'tcx> {
240232
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
241233
match *self {
@@ -480,15 +472,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
480472
}
481473
}
482474

483-
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
484-
type Lifted = ty::PredicateKind<'tcx>;
485-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
486-
match self {
487-
ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll),
488-
}
489-
}
490-
}
491-
492475
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
493476
type Lifted = ty::PredicateAtom<'tcx>;
494477
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
345345

346346
let infcx = self.selcx.infcx();
347347

348-
let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind();
348+
let binder = obligation.predicate.kind();
349349
if binder.skip_binder().has_escaping_bound_vars() {
350350
match binder.skip_binder() {
351351
// Evaluation will discard candidates using the leak check.

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>(
9494
// region relationships.
9595
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
9696
assert!(!obligation.has_escaping_bound_vars());
97-
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
97+
let binder = obligation.predicate.kind();
9898
if binder.skip_binder().has_escaping_bound_vars() {
9999
vec![]
100100
} else {

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
55
use rustc_middle::hir::map as hir_map;
66
use rustc_middle::ty::subst::Subst;
77
use rustc_middle::ty::{
8-
self, Binder, Predicate, PredicateAtom, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
8+
self, Binder, Predicate, PredicateAtom, ToPredicate, Ty, TyCtxt, WithConstness,
99
};
1010
use rustc_session::CrateDisambiguator;
1111
use rustc_span::symbol::Symbol;
@@ -379,7 +379,7 @@ fn well_formed_types_in_env<'tcx>(
379379
match arg.unpack() {
380380
GenericArgKind::Type(ty) => {
381381
let binder = Binder::dummy(PredicateAtom::TypeWellFormedFromEnv(ty));
382-
Some(tcx.mk_predicate(PredicateKind::ForAll(binder)))
382+
Some(tcx.mk_predicate(binder))
383383
}
384384

385385
// FIXME(eddyb) no WF conditions from lifetimes?

compiler/rustc_typeck/src/outlives/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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, _)| {
34-
let ty::PredicateKind::ForAll(binder) = out_pred.kind();
34+
let binder = out_pred.kind();
3535
match binder.skip_binder() {
3636
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
3737
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ 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-
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
118+
let binder = obligation.predicate.kind();
119119
match binder.skip_binder() {
120120
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
121121
if pred.def_id() == sized_trait {

0 commit comments

Comments
 (0)