mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Remove PredicateKind
This commit is contained in:
parent
4cb3d6f983
commit
4cd6f85a07
@ -9,12 +9,8 @@ pub fn anonymize_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pred: ty::Predicate<'tcx>,
|
||||
) -> ty::Predicate<'tcx> {
|
||||
match *pred.kind() {
|
||||
ty::PredicateKind::ForAll(binder) => {
|
||||
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
|
||||
tcx.reuse_or_mk_predicate(pred, new)
|
||||
}
|
||||
}
|
||||
let new = tcx.anonymize_late_bound_regions(pred.kind());
|
||||
tcx.reuse_or_mk_predicate(pred, new)
|
||||
}
|
||||
|
||||
struct PredicateSet<'tcx> {
|
||||
|
@ -44,9 +44,9 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
|
||||
type Variant = ty::PredicateKind<'tcx>;
|
||||
type Variant = ty::Binder<ty::PredicateAtom<'tcx>>;
|
||||
fn variant(&self) -> &Self::Variant {
|
||||
self.kind()
|
||||
self.kind_ref()
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,9 +226,9 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
|
||||
assert!(pos >= SHORTHAND_OFFSET);
|
||||
let shorthand = pos - SHORTHAND_OFFSET;
|
||||
|
||||
decoder.with_position(shorthand, ty::PredicateKind::decode)
|
||||
decoder.with_position(shorthand, ty::Binder::<ty::PredicateAtom<'tcx>>::decode)
|
||||
} else {
|
||||
ty::PredicateKind::decode(decoder)
|
||||
ty::Binder::<ty::PredicateAtom<'tcx>>::decode(decoder)
|
||||
}?;
|
||||
let predicate = decoder.tcx().mk_predicate(predicate_kind);
|
||||
Ok(predicate)
|
||||
|
@ -17,9 +17,9 @@ use crate::ty::query::{self, TyCtxtAt};
|
||||
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
|
||||
use crate::ty::TyKind::*;
|
||||
use crate::ty::{
|
||||
self, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, DefIdTree,
|
||||
ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntVar,
|
||||
IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
|
||||
self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
|
||||
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
|
||||
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateAtom, PredicateInner,
|
||||
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
|
||||
TyVid, TypeAndMut, Visibility,
|
||||
};
|
||||
@ -133,7 +133,7 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn intern_predicate(&self, kind: PredicateKind<'tcx>) -> &'tcx PredicateInner<'tcx> {
|
||||
fn intern_predicate(&self, kind: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
|
||||
self.predicate
|
||||
.intern(kind, |kind| {
|
||||
let flags = super::flags::FlagComputation::for_predicate(kind);
|
||||
@ -1948,8 +1948,8 @@ impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateInner<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
|
||||
impl<'tcx> Borrow<Binder<PredicateAtom<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a Binder<PredicateAtom<'tcx>> {
|
||||
&self.0.kind
|
||||
}
|
||||
}
|
||||
@ -1987,12 +1987,6 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! direct_interners {
|
||||
($($name:ident: $method:ident($ty:ty),)+) => {
|
||||
$(impl<'tcx> PartialEq for Interned<'tcx, $ty> {
|
||||
@ -2091,7 +2085,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
|
||||
pub fn mk_predicate(self, kind: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
|
||||
let inner = self.interners.intern_predicate(kind);
|
||||
Predicate { inner }
|
||||
}
|
||||
@ -2100,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn reuse_or_mk_predicate(
|
||||
self,
|
||||
pred: Predicate<'tcx>,
|
||||
kind: PredicateKind<'tcx>,
|
||||
kind: Binder<PredicateAtom<'tcx>>,
|
||||
) -> Predicate<'tcx> {
|
||||
if *pred.kind() != kind { self.mk_predicate(kind) } else { pred }
|
||||
if pred.kind() != kind { self.mk_predicate(kind) } else { pred }
|
||||
}
|
||||
|
||||
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||
|
@ -22,7 +22,7 @@ impl FlagComputation {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn for_predicate(kind: ty::PredicateKind<'_>) -> FlagComputation {
|
||||
pub fn for_predicate(kind: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
|
||||
let mut result = FlagComputation::new();
|
||||
result.add_predicate_kind(kind);
|
||||
result
|
||||
@ -204,8 +204,7 @@ impl FlagComputation {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
|
||||
let ty::PredicateKind::ForAll(binder) = kind;
|
||||
fn add_predicate_kind(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
|
||||
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
|
||||
}
|
||||
|
||||
|
@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> {
|
||||
|
||||
#[derive(Debug)]
|
||||
crate struct PredicateInner<'tcx> {
|
||||
kind: PredicateKind<'tcx>,
|
||||
kind: Binder<PredicateAtom<'tcx>>,
|
||||
flags: TypeFlags,
|
||||
/// See the comment for the corresponding field of [TyS].
|
||||
outer_exclusive_binder: ty::DebruijnIndex,
|
||||
@ -1061,7 +1061,12 @@ impl<'tcx> Eq for Predicate<'tcx> {}
|
||||
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
#[inline(always)]
|
||||
pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
|
||||
pub fn kind(self) -> Binder<PredicateAtom<'tcx>> {
|
||||
self.inner.kind
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn kind_ref(&self) -> &Binder<PredicateAtom<'tcx>> {
|
||||
&self.inner.kind
|
||||
}
|
||||
|
||||
@ -1072,7 +1077,7 @@ impl<'tcx> Predicate<'tcx> {
|
||||
///
|
||||
/// Note that this method panics in case this predicate has unbound variables.
|
||||
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
|
||||
let &PredicateKind::ForAll(binder) = self.kind();
|
||||
let binder = self.kind();
|
||||
binder.skip_binder()
|
||||
}
|
||||
|
||||
@ -1083,21 +1088,21 @@ impl<'tcx> Predicate<'tcx> {
|
||||
/// Rebinding the returned atom can causes the previously bound variables
|
||||
/// to end up at the wrong binding level.
|
||||
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
|
||||
let &PredicateKind::ForAll(binder) = self.kind();
|
||||
let binder = self.kind();
|
||||
binder.skip_binder()
|
||||
}
|
||||
|
||||
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
|
||||
/// `Atom`, then it is not allowed to contain escaping bound vars.
|
||||
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
|
||||
let &PredicateKind::ForAll(binder) = self.kind();
|
||||
let binder = self.kind();
|
||||
binder
|
||||
}
|
||||
|
||||
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
|
||||
/// contained unbound variables by shifting these variables outwards.
|
||||
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
|
||||
let &PredicateKind::ForAll(binder) = self.kind();
|
||||
let binder = self.kind();
|
||||
binder
|
||||
}
|
||||
}
|
||||
@ -1117,13 +1122,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable, TypeFoldable)]
|
||||
pub enum PredicateKind<'tcx> {
|
||||
/// `for<'a>: ...`
|
||||
ForAll(Binder<PredicateAtom<'tcx>>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable, TypeFoldable)]
|
||||
pub enum PredicateAtom<'tcx> {
|
||||
@ -1175,7 +1173,7 @@ pub enum PredicateAtom<'tcx> {
|
||||
impl<'tcx> Binder<PredicateAtom<'tcx>> {
|
||||
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
|
||||
pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::ForAll(self).to_predicate(tcx)
|
||||
self.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1387,7 +1385,7 @@ pub trait ToPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>;
|
||||
}
|
||||
|
||||
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
|
||||
impl ToPredicate<'tcx> for Binder<PredicateAtom<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(self)
|
||||
@ -1398,7 +1396,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self);
|
||||
tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self)))
|
||||
tcx.mk_predicate(Binder::dummy(self))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2068,7 +2068,7 @@ define_print_and_forward_display! {
|
||||
}
|
||||
|
||||
ty::Predicate<'tcx> {
|
||||
let ty::PredicateKind::ForAll(binder) = self.kind();
|
||||
let binder = self.kind();
|
||||
p!(print(binder))
|
||||
}
|
||||
|
||||
|
@ -228,14 +228,6 @@ impl fmt::Debug for ty::Predicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::PredicateKind<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::PredicateAtom<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
@ -480,15 +472,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
|
||||
type Lifted = ty::PredicateKind<'tcx>;
|
||||
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
||||
match self {
|
||||
ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
|
||||
type Lifted = ty::PredicateAtom<'tcx>;
|
||||
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
||||
|
@ -345,7 +345,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
let infcx = self.selcx.infcx();
|
||||
|
||||
let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind();
|
||||
let binder = obligation.predicate.kind();
|
||||
if binder.skip_binder().has_escaping_bound_vars() {
|
||||
match binder.skip_binder() {
|
||||
// Evaluation will discard candidates using the leak check.
|
||||
|
@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
// region relationships.
|
||||
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
|
||||
assert!(!obligation.has_escaping_bound_vars());
|
||||
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
|
||||
let binder = obligation.predicate.kind();
|
||||
if binder.skip_binder().has_escaping_bound_vars() {
|
||||
vec![]
|
||||
} else {
|
||||
|
@ -5,7 +5,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_middle::hir::map as hir_map;
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, Predicate, PredicateAtom, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
|
||||
self, Binder, Predicate, PredicateAtom, ToPredicate, Ty, TyCtxt, WithConstness,
|
||||
};
|
||||
use rustc_session::CrateDisambiguator;
|
||||
use rustc_span::symbol::Symbol;
|
||||
@ -379,7 +379,7 @@ fn well_formed_types_in_env<'tcx>(
|
||||
match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => {
|
||||
let binder = Binder::dummy(PredicateAtom::TypeWellFormedFromEnv(ty));
|
||||
Some(tcx.mk_predicate(PredicateKind::ForAll(binder)))
|
||||
Some(tcx.mk_predicate(binder))
|
||||
}
|
||||
|
||||
// FIXME(eddyb) no WF conditions from lifetimes?
|
||||
|
@ -31,7 +31,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
|
||||
let mut pred: Vec<String> = predicates
|
||||
.iter()
|
||||
.map(|(out_pred, _)| {
|
||||
let ty::PredicateKind::ForAll(binder) = out_pred.kind();
|
||||
let binder = out_pred.kind();
|
||||
match binder.skip_binder() {
|
||||
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
|
||||
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
|
||||
|
@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||
.filter(|p| !p.is_global())
|
||||
.filter_map(|obligation| {
|
||||
// Note that we do not want to deal with qualified predicates here.
|
||||
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
|
||||
let binder = obligation.predicate.kind();
|
||||
match binder.skip_binder() {
|
||||
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
|
||||
if pred.def_id() == sized_trait {
|
||||
|
Loading…
Reference in New Issue
Block a user