Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnr

Remove PredicateKind and instead only use Binder<PredicateAtom>

Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171

r? `@lcnr`
This commit is contained in:
bors 2021-01-17 20:49:11 +00:00
commit 4253153db2
71 changed files with 652 additions and 756 deletions

View File

@ -530,10 +530,10 @@ fn query_outlives_constraints_into_obligations<'a>(
let atom = match k1.unpack() {
GenericArgKind::Lifetime(r1) => {
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
}
GenericArgKind::Type(t1) => {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
}
GenericArgKind::Const(..) => {
// Consts cannot outlive one another, so we don't expect to
@ -541,8 +541,7 @@ fn query_outlives_constraints_into_obligations<'a>(
span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
}
};
let predicate =
predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
let predicate = predicate.rebind(atom).to_predicate(self.tcx);
Obligation::new(cause.clone(), param_env, predicate)
})
@ -664,7 +663,7 @@ fn push_outlives(&mut self, sup: ty::Region<'tcx>, sub: ty::Region<'tcx>) {
self.obligations.push(Obligation {
cause: self.cause.clone(),
param_env: self.param_env,
predicate: ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(sup, sub))
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
.to_predicate(self.infcx.tcx),
recursion_depth: 0,
});

View File

@ -358,7 +358,7 @@ pub fn instantiate(
self.obligations.push(Obligation::new(
self.trace.cause.clone(),
self.param_env,
ty::PredicateAtom::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
));
}
@ -451,9 +451,9 @@ pub fn add_const_equate_obligation(
b: &'tcx ty::Const<'tcx>,
) {
let predicate = if a_is_expected {
ty::PredicateAtom::ConstEquate(a, b)
ty::PredicateKind::ConstEquate(a, b)
} else {
ty::PredicateAtom::ConstEquate(b, a)
ty::PredicateKind::ConstEquate(b, a)
};
self.obligations.push(Obligation::new(
self.trace.cause.clone(),

View File

@ -1706,8 +1706,8 @@ pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
for (predicate, _) in bounds {
let predicate = predicate.subst(self.tcx, substs);
if let ty::PredicateAtom::Projection(projection_predicate) =
predicate.skip_binders()
if let ty::PredicateKind::Projection(projection_predicate) =
predicate.kind().skip_binder()
{
if projection_predicate.projection_ty.item_def_id == item_def_id {
// We don't account for multiple `Future::Output = Ty` contraints.

View File

@ -6,7 +6,6 @@
use rustc_middle::traits::query::OutlivesBound;
use rustc_middle::ty;
use rustc_middle::ty::fold::TypeFoldable;
pub fn explicit_outlives_bounds<'tcx>(
param_env: ty::ParamEnv<'tcx>,
@ -15,20 +14,20 @@ pub fn explicit_outlives_bounds<'tcx>(
param_env
.caller_bounds()
.into_iter()
.map(ty::Predicate::skip_binders)
.filter(|atom| !atom.has_escaping_bound_vars())
.filter_map(move |atom| match atom {
ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::TypeOutlives(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
.map(ty::Predicate::kind)
.filter_map(ty::Binder::no_bound_vars)
.filter_map(move |kind| match kind {
ty::PredicateKind::Projection(..)
| ty::PredicateKind::Trait(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::TypeOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
}
})

View File

@ -100,7 +100,7 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
self.fields.obligations.push(Obligation::new(
self.fields.trace.cause.clone(),
self.fields.param_env,
ty::PredicateAtom::Subtype(ty::SubtypePredicate {
ty::PredicateKind::Subtype(ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
b,

View File

@ -9,13 +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)
}
ty::PredicateKind::Atom(_) => pred,
}
let new = tcx.anonymize_late_bound_regions(pred.kind());
tcx.reuse_or_mk_predicate(pred, new)
}
struct PredicateSet<'tcx> {
@ -126,9 +121,9 @@ pub fn filter_to_traits(self) -> FilterToTraits<Self> {
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
ty::PredicateKind::Trait(data, _) => {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());
@ -150,36 +145,36 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
self.stack.extend(obligations);
}
ty::PredicateAtom::WellFormed(..) => {
ty::PredicateKind::WellFormed(..) => {
// Currently, we do not elaborate WF predicates,
// although we easily could.
}
ty::PredicateAtom::ObjectSafe(..) => {
ty::PredicateKind::ObjectSafe(..) => {
// Currently, we do not elaborate object-safe
// predicates.
}
ty::PredicateAtom::Subtype(..) => {
ty::PredicateKind::Subtype(..) => {
// Currently, we do not "elaborate" predicates like `X <: Y`,
// though conceivably we might.
}
ty::PredicateAtom::Projection(..) => {
ty::PredicateKind::Projection(..) => {
// Nothing to elaborate in a projection predicate.
}
ty::PredicateAtom::ClosureKind(..) => {
ty::PredicateKind::ClosureKind(..) => {
// Nothing to elaborate when waiting for a closure's kind to be inferred.
}
ty::PredicateAtom::ConstEvaluatable(..) => {
ty::PredicateKind::ConstEvaluatable(..) => {
// Currently, we do not elaborate const-evaluatable
// predicates.
}
ty::PredicateAtom::ConstEquate(..) => {
ty::PredicateKind::ConstEquate(..) => {
// Currently, we do not elaborate const-equate
// predicates.
}
ty::PredicateAtom::RegionOutlives(..) => {
ty::PredicateKind::RegionOutlives(..) => {
// Nothing to elaborate from `'a: 'b`.
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
// We know that `T: 'a` for some type `T`. We can
// often elaborate this. For example, if we know that
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@ -209,7 +204,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
if r.is_late_bound() {
None
} else {
Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
r, r_min,
)))
}
@ -217,7 +212,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name);
Some(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty, r_min,
)))
}
@ -242,7 +237,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
}),
);
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
// Nothing to elaborate
}
}

View File

@ -1550,13 +1550,13 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PredicateAtom::*;
use rustc_middle::ty::PredicateKind::*;
if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let predicates = cx.tcx.predicates_of(def_id);
for &(predicate, span) in predicates.predicates {
let predicate_kind_name = match predicate.skip_binders() {
let predicate_kind_name = match predicate.kind().skip_binder() {
Trait(..) => "Trait",
TypeOutlives(..) |
RegionOutlives(..) => "Lifetime",
@ -1936,8 +1936,8 @@ fn lifetimes_outliving_lifetime<'tcx>(
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
_ => None,
},
@ -1952,8 +1952,8 @@ fn lifetimes_outliving_type<'tcx>(
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
a.is_param(index).then_some(b)
}
_ => None,

View File

@ -45,12 +45,12 @@
impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty::PredicateAtom::*;
use rustc_middle::ty::PredicateKind::*;
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let predicates = cx.tcx.explicit_predicates_of(def_id);
for &(predicate, span) in predicates.predicates {
let trait_predicate = match predicate.skip_binders() {
let trait_predicate = match predicate.kind().skip_binder() {
Trait(trait_predicate, _constness) => trait_predicate,
_ => continue,
};

View File

@ -202,8 +202,8 @@ fn check_must_use_ty<'tcx>(
let mut has_emitted = false;
for &(predicate, _) in cx.tcx.explicit_item_bounds(def) {
// We only look at the `DefId`, so it is safe to skip the binder here.
if let ty::PredicateAtom::Trait(ref poly_trait_predicate, _) =
predicate.skip_binders()
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
predicate.kind().skip_binder()
{
let def_id = poly_trait_predicate.trait_ref.def_id;
let descr_pre =

View File

@ -46,7 +46,7 @@ pub(super) struct EncodeContext<'a, 'tcx> {
lazy_state: LazyState,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::PredicateKind<'tcx>, usize>,
interpret_allocs: FxIndexSet<interpret::AllocId>,
@ -328,7 +328,7 @@ fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
&mut self.type_shorthands
}
fn predicate_shorthands(&mut self) -> &mut FxHashMap<rustc_middle::ty::Predicate<'tcx>, usize> {
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize> {
&mut self.predicate_shorthands
}

View File

@ -43,10 +43,12 @@ fn variant(&self) -> &Self::Variant {
}
}
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::PredicateKind<'tcx> {
type Variant = ty::PredicateKind<'tcx>;
#[inline]
fn variant(&self) -> &Self::Variant {
self.kind()
self
}
}
@ -55,7 +57,7 @@ pub trait TyEncoder<'tcx>: Encoder {
fn position(&self) -> usize;
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>;
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize>;
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize>;
fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>;
}
@ -118,9 +120,15 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
}
}
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Binder<ty::PredicateKind<'tcx>> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
encode_with_shorthand(e, &self.skip_binder(), TyEncoder::predicate_shorthands)
}
}
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Predicate<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
encode_with_shorthand(e, self, TyEncoder::predicate_shorthands)
self.kind().encode(e)
}
}
@ -218,18 +226,24 @@ fn decode(decoder: &mut D) -> Result<Ty<'tcx>, D::Error> {
}
}
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
fn decode(decoder: &mut D) -> Result<ty::Predicate<'tcx>, D::Error> {
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Binder<ty::PredicateKind<'tcx>> {
fn decode(decoder: &mut D) -> Result<ty::Binder<ty::PredicateKind<'tcx>>, D::Error> {
// Handle shorthands first, if we have an usize > 0x80.
let predicate_kind = if decoder.positioned_at_shorthand() {
Ok(ty::Binder::bind(if decoder.positioned_at_shorthand() {
let pos = decoder.read_usize()?;
assert!(pos >= SHORTHAND_OFFSET);
let shorthand = pos - SHORTHAND_OFFSET;
decoder.with_position(shorthand, ty::PredicateKind::decode)
decoder.with_position(shorthand, ty::PredicateKind::decode)?
} else {
ty::PredicateKind::decode(decoder)
}?;
ty::PredicateKind::decode(decoder)?
}))
}
}
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
fn decode(decoder: &mut D) -> Result<ty::Predicate<'tcx>, D::Error> {
let predicate_kind = Decodable::decode(decoder)?;
let predicate = decoder.tcx().mk_predicate(predicate_kind);
Ok(predicate)
}
@ -457,3 +471,28 @@ fn error(&mut self, err: &str) -> Self::Error {
}
}
}
macro_rules! impl_binder_encode_decode {
($($t:ty),+ $(,)?) => {
$(
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Binder<$t> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.as_ref().skip_binder().encode(e)
}
}
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Binder<$t> {
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
Ok(ty::Binder::bind(Decodable::decode(decoder)?))
}
}
)*
}
}
impl_binder_encode_decode! {
&'tcx ty::List<Ty<'tcx>>,
ty::FnSig<'tcx>,
ty::ExistentialPredicate<'tcx>,
ty::TraitRef<'tcx>,
Vec<ty::GeneratorInteriorTypeCause<'tcx>>,
}

View File

@ -18,9 +18,9 @@
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, PredicateInner, PredicateKind,
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
TyVid, TypeAndMut, Visibility,
};
@ -134,7 +134,7 @@ fn intern_ty(&self, kind: TyKind<'tcx>) -> Ty<'tcx> {
}
#[inline(never)]
fn intern_predicate(&self, kind: PredicateKind<'tcx>) -> &'tcx PredicateInner<'tcx> {
fn intern_predicate(&self, kind: Binder<PredicateKind<'tcx>>) -> &'tcx PredicateInner<'tcx> {
self.predicate
.intern(kind, |kind| {
let flags = super::flags::FlagComputation::for_predicate(kind);
@ -1951,8 +1951,8 @@ fn hash<H: Hasher>(&self, s: &mut H) {
}
}
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateInner<'tcx>> {
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
impl<'tcx> Borrow<Binder<PredicateKind<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
fn borrow<'a>(&'a self) -> &'a Binder<PredicateKind<'tcx>> {
&self.0.kind
}
}
@ -1990,12 +1990,6 @@ fn borrow<'a>(&'a self) -> &'a 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> {
@ -2094,8 +2088,8 @@ pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
}
#[inline]
pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
let inner = self.interners.intern_predicate(kind);
pub fn mk_predicate(self, binder: Binder<PredicateKind<'tcx>>) -> Predicate<'tcx> {
let inner = self.interners.intern_predicate(binder);
Predicate { inner }
}
@ -2103,9 +2097,9 @@ pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
pub fn reuse_or_mk_predicate(
self,
pred: Predicate<'tcx>,
kind: PredicateKind<'tcx>,
binder: Binder<PredicateKind<'tcx>>,
) -> Predicate<'tcx> {
if *pred.kind() != kind { self.mk_predicate(kind) } else { pred }
if pred.kind() != binder { self.mk_predicate(binder) } else { pred }
}
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {

View File

@ -22,9 +22,9 @@ pub fn for_kind(kind: &ty::TyKind<'_>) -> FlagComputation {
result
}
pub fn for_predicate(kind: ty::PredicateKind<'_>) -> FlagComputation {
pub fn for_predicate(binder: ty::Binder<ty::PredicateKind<'_>>) -> FlagComputation {
let mut result = FlagComputation::new();
result.add_predicate_kind(kind);
result.add_predicate(binder);
result
}
@ -204,53 +204,46 @@ fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
}
}
fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
match kind {
ty::PredicateKind::ForAll(binder) => {
self.bound_computation(binder, |computation, atom| {
computation.add_predicate_atom(atom)
});
}
ty::PredicateKind::Atom(atom) => self.add_predicate_atom(atom),
}
fn add_predicate(&mut self, binder: ty::Binder<ty::PredicateKind<'_>>) {
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
}
fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) {
fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) {
match atom {
ty::PredicateAtom::Trait(trait_pred, _constness) => {
ty::PredicateKind::Trait(trait_pred, _constness) => {
self.add_substs(trait_pred.trait_ref.substs);
}
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
self.add_region(a);
self.add_region(b);
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
self.add_ty(ty);
self.add_region(region);
}
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
self.add_ty(a);
self.add_ty(b);
}
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
self.add_projection_ty(projection_ty);
self.add_ty(ty);
}
ty::PredicateAtom::WellFormed(arg) => {
ty::PredicateKind::WellFormed(arg) => {
self.add_substs(slice::from_ref(&arg));
}
ty::PredicateAtom::ObjectSafe(_def_id) => {}
ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
ty::PredicateKind::ObjectSafe(_def_id) => {}
ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
self.add_substs(substs);
}
ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(_def_id, substs) => {
self.add_substs(substs);
}
ty::PredicateAtom::ConstEquate(expected, found) => {
ty::PredicateKind::ConstEquate(expected, found) => {
self.add_const(expected);
self.add_const(found);
}
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
self.add_ty(ty);
}
}

View File

@ -1069,14 +1069,14 @@ fn instantiate_identity_into(
#[derive(Debug)]
crate struct PredicateInner<'tcx> {
kind: PredicateKind<'tcx>,
kind: Binder<PredicateKind<'tcx>>,
flags: TypeFlags,
/// See the comment for the corresponding field of [TyS].
outer_exclusive_binder: ty::DebruijnIndex,
}
#[cfg(target_arch = "x86_64")]
static_assert_size!(PredicateInner<'_>, 48);
static_assert_size!(PredicateInner<'_>, 40);
#[derive(Clone, Copy, Lift)]
pub struct Predicate<'tcx> {
@ -1099,59 +1099,9 @@ fn hash<H: Hasher>(&self, s: &mut H) {
impl<'tcx> Eq for Predicate<'tcx> {}
impl<'tcx> Predicate<'tcx> {
#[inline(always)]
pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
&self.inner.kind
}
/// Returns the inner `PredicateAtom`.
///
/// The returned atom may contain unbound variables bound to binders skipped in this method.
/// It is safe to reapply binders to the given atom.
///
/// Note that this method panics in case this predicate has unbound variables.
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder.skip_binder(),
&PredicateKind::Atom(atom) => {
debug_assert!(!atom.has_escaping_bound_vars());
atom
}
}
}
/// Returns the inner `PredicateAtom`.
///
/// Note that this method does not check if the predicate has unbound variables.
///
/// 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> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder.skip_binder(),
&PredicateKind::Atom(atom) => atom,
}
}
/// 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>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => {
debug_assert!(!atom.has_escaping_bound_vars());
Binder::dummy(atom)
}
}
}
/// 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>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
}
/// Gets the inner `Binder<PredicateKind<'tcx>>`.
pub fn kind(self) -> Binder<PredicateKind<'tcx>> {
self.inner.kind
}
}
@ -1173,14 +1123,6 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable)]
pub enum PredicateKind<'tcx> {
/// `for<'a>: ...`
ForAll(Binder<PredicateAtom<'tcx>>),
Atom(PredicateAtom<'tcx>),
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable)]
pub enum PredicateAtom<'tcx> {
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
/// the `Self` type of the trait reference and `A`, `B`, and `C`
/// would be the type parameters.
@ -1226,21 +1168,6 @@ pub enum PredicateAtom<'tcx> {
TypeWellFormedFromEnv(Ty<'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>,
qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
) -> Predicate<'tcx> {
match self.no_bound_vars() {
Some(atom) => PredicateKind::Atom(atom),
None => qualifier(self),
}
.to_predicate(tcx)
}
}
/// The crate outlives map is computed during typeck and contains the
/// outlives of every item in the local crate. You should not use it
/// directly, because to do so will make your pass dependent on the
@ -1326,13 +1253,9 @@ pub fn subst_supertrait(
// from the substitution and the value being substituted into, and
// this trick achieves that).
let substs = trait_ref.skip_binder().substs;
let pred = self.skip_binders();
let pred = self.kind().skip_binder();
let new = pred.subst(tcx, substs);
if new != pred {
ty::Binder::bind(new).potentially_quantified(tcx, PredicateKind::ForAll)
} else {
self
}
tcx.reuse_or_mk_predicate(self, ty::Binder::bind(new))
}
}
@ -1453,24 +1376,23 @@ pub trait ToPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>;
}
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
impl ToPredicate<'tcx> for Binder<PredicateKind<'tcx>> {
#[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
tcx.mk_predicate(self)
}
}
impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
impl ToPredicate<'tcx> for PredicateKind<'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::Atom(self))
tcx.mk_predicate(Binder::dummy(self))
}
}
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateAtom::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
.to_predicate(tcx)
}
}
@ -1487,66 +1409,62 @@ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.value
.map_bound(|value| PredicateAtom::Trait(value, self.constness))
.potentially_quantified(tcx, PredicateKind::ForAll)
self.value.map_bound(|value| PredicateKind::Trait(value, self.constness)).to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateAtom::RegionOutlives)
.potentially_quantified(tcx, PredicateKind::ForAll)
self.map_bound(PredicateKind::RegionOutlives).to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateAtom::TypeOutlives)
.potentially_quantified(tcx, PredicateKind::ForAll)
self.map_bound(PredicateKind::TypeOutlives).to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll)
self.map_bound(PredicateKind::Projection).to_predicate(tcx)
}
}
impl<'tcx> Predicate<'tcx> {
pub fn to_opt_poly_trait_ref(self) -> Option<ConstnessAnd<PolyTraitRef<'tcx>>> {
let predicate = self.bound_atom();
let predicate = self.kind();
match predicate.skip_binder() {
PredicateAtom::Trait(t, constness) => {
PredicateKind::Trait(t, constness) => {
Some(ConstnessAnd { constness, value: predicate.rebind(t.trait_ref) })
}
PredicateAtom::Projection(..)
| PredicateAtom::Subtype(..)
| PredicateAtom::RegionOutlives(..)
| PredicateAtom::WellFormed(..)
| PredicateAtom::ObjectSafe(..)
| PredicateAtom::ClosureKind(..)
| PredicateAtom::TypeOutlives(..)
| PredicateAtom::ConstEvaluatable(..)
| PredicateAtom::ConstEquate(..)
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
| PredicateKind::WellFormed(..)
| PredicateKind::ObjectSafe(..)
| PredicateKind::ClosureKind(..)
| PredicateKind::TypeOutlives(..)
| PredicateKind::ConstEvaluatable(..)
| PredicateKind::ConstEquate(..)
| PredicateKind::TypeWellFormedFromEnv(..) => None,
}
}
pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
let predicate = self.bound_atom();
let predicate = self.kind();
match predicate.skip_binder() {
PredicateAtom::TypeOutlives(data) => Some(predicate.rebind(data)),
PredicateAtom::Trait(..)
| PredicateAtom::Projection(..)
| PredicateAtom::Subtype(..)
| PredicateAtom::RegionOutlives(..)
| PredicateAtom::WellFormed(..)
| PredicateAtom::ObjectSafe(..)
| PredicateAtom::ClosureKind(..)
| PredicateAtom::ConstEvaluatable(..)
| PredicateAtom::ConstEquate(..)
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
PredicateKind::TypeOutlives(data) => Some(predicate.rebind(data)),
PredicateKind::Trait(..)
| PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
| PredicateKind::WellFormed(..)
| PredicateKind::ObjectSafe(..)
| PredicateKind::ClosureKind(..)
| PredicateKind::ConstEvaluatable(..)
| PredicateKind::ConstEquate(..)
| PredicateKind::TypeWellFormedFromEnv(..) => None,
}
}
}

View File

@ -623,12 +623,8 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
p!("impl");
for (predicate, _) in bounds {
let predicate = predicate.subst(self.tcx(), substs);
// Note: We can't use `to_opt_poly_trait_ref` here as `predicate`
// may contain unbound variables. We therefore do this manually.
//
// FIXME(lcnr): Find out why exactly this is the case :)
let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx());
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let bound_predicate = predicate.kind();
if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() {
let trait_ref = bound_predicate.rebind(pred.trait_ref);
// Don't print +Sized, but rather +?Sized if absent.
if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() {
@ -2068,40 +2064,38 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
}
ty::Predicate<'tcx> {
match self.kind() {
&ty::PredicateKind::Atom(atom) => p!(print(atom)),
ty::PredicateKind::ForAll(binder) => p!(print(binder)),
}
let binder = self.kind();
p!(print(binder))
}
ty::PredicateAtom<'tcx> {
ty::PredicateKind<'tcx> {
match *self {
ty::PredicateAtom::Trait(ref data, constness) => {
ty::PredicateKind::Trait(ref data, constness) => {
if let hir::Constness::Const = constness {
p!("const ");
}
p!(print(data))
}
ty::PredicateAtom::Subtype(predicate) => p!(print(predicate)),
ty::PredicateAtom::RegionOutlives(predicate) => p!(print(predicate)),
ty::PredicateAtom::TypeOutlives(predicate) => p!(print(predicate)),
ty::PredicateAtom::Projection(predicate) => p!(print(predicate)),
ty::PredicateAtom::WellFormed(arg) => p!(print(arg), " well-formed"),
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"),
ty::PredicateKind::ObjectSafe(trait_def_id) => {
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
}
ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
p!("the closure `",
print_value_path(closure_def_id, &[]),
write("` implements the trait `{}`", kind))
}
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
ty::PredicateKind::ConstEvaluatable(def, substs) => {
p!("the constant `", print_value_path(def.did, substs), "` can be evaluated")
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
p!("the constant `", print(c1), "` equals `", print(c2), "`")
}
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
p!("the type `", print(ty), "` is found in the environment")
}
}

View File

@ -989,7 +989,7 @@ struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
tcx: TyCtxt<'tcx>,
encoder: &'a mut E,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::PredicateKind<'tcx>, usize>,
interpret_allocs: FxIndexSet<interpret::AllocId>,
source_map: CachingSourceMapView<'tcx>,
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
@ -1103,7 +1103,7 @@ fn position(&self) -> usize {
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
&mut self.type_shorthands
}
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize> {
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize> {
&mut self.predicate_shorthands
}
fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> {

View File

@ -231,37 +231,28 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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),
ty::PredicateKind::Atom(atom) => write!(f, "{:?}", atom),
}
}
}
impl fmt::Debug for ty::PredicateAtom<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::PredicateAtom::Trait(ref a, constness) => {
ty::PredicateKind::Trait(ref a, constness) => {
if let hir::Constness::Const = constness {
write!(f, "const ")?;
}
a.fmt(f)
}
ty::PredicateAtom::Subtype(ref pair) => pair.fmt(f),
ty::PredicateAtom::RegionOutlives(ref pair) => pair.fmt(f),
ty::PredicateAtom::TypeOutlives(ref pair) => pair.fmt(f),
ty::PredicateAtom::Projection(ref pair) => pair.fmt(f),
ty::PredicateAtom::WellFormed(data) => write!(f, "WellFormed({:?})", data),
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
ty::PredicateKind::ObjectSafe(trait_def_id) => {
write!(f, "ObjectSafe({:?})", trait_def_id)
}
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
}
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
}
ty::PredicateAtom::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
write!(f, "TypeWellFormedFromEnv({:?})", ty)
}
}
@ -485,46 +476,36 @@ 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),
ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom),
}
}
}
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> {
match self {
ty::PredicateAtom::Trait(data, constness) => {
tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness))
ty::PredicateKind::Trait(data, constness) => {
tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness))
}
ty::PredicateAtom::Subtype(data) => tcx.lift(data).map(ty::PredicateAtom::Subtype),
ty::PredicateAtom::RegionOutlives(data) => {
tcx.lift(data).map(ty::PredicateAtom::RegionOutlives)
ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
ty::PredicateKind::RegionOutlives(data) => {
tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
}
ty::PredicateAtom::TypeOutlives(data) => {
tcx.lift(data).map(ty::PredicateAtom::TypeOutlives)
ty::PredicateKind::TypeOutlives(data) => {
tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
}
ty::PredicateAtom::Projection(data) => {
tcx.lift(data).map(ty::PredicateAtom::Projection)
ty::PredicateKind::Projection(data) => {
tcx.lift(data).map(ty::PredicateKind::Projection)
}
ty::PredicateAtom::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateAtom::WellFormed),
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKind::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateKind::WellFormed),
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
tcx.lift(closure_substs).map(|closure_substs| {
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind)
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
})
}
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
Some(ty::PredicateAtom::ObjectSafe(trait_def_id))
ty::PredicateKind::ObjectSafe(trait_def_id) => {
Some(ty::PredicateKind::ObjectSafe(trait_def_id))
}
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
tcx.lift(substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs))
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
tcx.lift(substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs))
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
ty::PredicateKind::ConstEquate(c1, c2) => {
tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
}
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
tcx.lift(ty).map(ty::PredicateAtom::TypeWellFormedFromEnv)
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
tcx.lift(ty).map(ty::PredicateKind::TypeWellFormedFromEnv)
}
}
}
@ -1036,12 +1017,12 @@ fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::Br
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder);
let new = self.inner.kind.fold_with(folder);
folder.tcx().reuse_or_mk_predicate(self, new)
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
ty::PredicateKind::super_visit_with(&self.inner.kind, visitor)
self.inner.kind.visit_with(visitor)
}
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {

View File

@ -955,7 +955,9 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::PolyTrai
/// erase, or otherwise "discharge" these bound vars, we change the
/// type from `Binder<T>` to just `T` (see
/// e.g., `liberate_late_bound_regions`).
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
///
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Binder<T>(T);
impl<T> Binder<T> {

View File

@ -590,8 +590,8 @@ fn add_static_impl_trait_suggestion(
let mut found = false;
for (bound, _) in bounds {
if let ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_, r)) =
bound.skip_binders()
if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
bound.kind().skip_binder()
{
let r = r.subst(self.infcx.tcx, substs);
if let ty::RegionKind::ReStatic = r {

View File

@ -1014,7 +1014,7 @@ fn check_user_type_annotations(&mut self) {
}
self.prove_predicate(
ty::PredicateAtom::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
Locations::All(span),
ConstraintCategory::TypeAnnotation,
);
@ -1266,7 +1266,7 @@ fn eq_opaque_type_and_type(
obligations.obligations.push(traits::Obligation::new(
ObligationCause::dummy(),
param_env,
ty::PredicateAtom::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
));
obligations.add(
infcx
@ -1611,7 +1611,7 @@ fn check_terminator(
self.check_call_dest(body, term, &sig, destination, term_location);
self.prove_predicates(
sig.inputs_and_output.iter().map(|ty| ty::PredicateAtom::WellFormed(ty.into())),
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
term_location.to_locations(),
ConstraintCategory::Boring,
);
@ -2694,7 +2694,7 @@ fn prove_trait_ref(
category: ConstraintCategory,
) {
self.prove_predicates(
Some(ty::PredicateAtom::Trait(
Some(ty::PredicateKind::Trait(
ty::TraitPredicate { trait_ref },
hir::Constness::NotConst,
)),

View File

@ -411,24 +411,24 @@ fn check_item_predicates(&mut self) {
loop {
let predicates = tcx.predicates_of(current);
for (predicate, _) in predicates.predicates {
match predicate.skip_binders() {
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::Projection(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
ty::PredicateAtom::ObjectSafe(_) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::Projection(_)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
ty::PredicateKind::ObjectSafe(_) => {
bug!("object safe predicate on function: {:#?}", predicate)
}
ty::PredicateAtom::ClosureKind(..) => {
ty::PredicateKind::ClosureKind(..) => {
bug!("closure kind predicate on function: {:#?}", predicate)
}
ty::PredicateAtom::Subtype(_) => {
ty::PredicateKind::Subtype(_) => {
bug!("subtype predicate on function: {:#?}", predicate)
}
ty::PredicateAtom::Trait(pred, constness) => {
ty::PredicateKind::Trait(pred, constness) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}

View File

@ -5,7 +5,7 @@
use rustc_middle::ty::{
self,
subst::{GenericArgKind, Subst, SubstsRef},
PredicateAtom, Ty, TyCtxt, TyS,
PredicateKind, Ty, TyCtxt, TyS,
};
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
use rustc_span::{symbol::sym, Span};
@ -105,7 +105,7 @@ fn check_bound_args(
let param_env = self.tcx.param_env(def_id);
let bounds = param_env.caller_bounds();
for bound in bounds {
if let Some(bound_ty) = self.is_pointer_trait(&bound.skip_binders()) {
if let Some(bound_ty) = self.is_pointer_trait(&bound.kind().skip_binder()) {
// Get the argument types as they appear in the function signature.
let arg_defs = self.tcx.fn_sig(def_id).skip_binder().inputs();
for (arg_num, arg_def) in arg_defs.iter().enumerate() {
@ -131,8 +131,8 @@ fn check_bound_args(
}
/// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type.
fn is_pointer_trait(&self, bound: &PredicateAtom<'tcx>) -> Option<Ty<'tcx>> {
if let ty::PredicateAtom::Trait(predicate, _) = bound {
fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option<Ty<'tcx>> {
if let ty::PredicateKind::Trait(predicate, _) = bound {
if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) {
Some(predicate.trait_ref.self_ty())
} else {

View File

@ -100,19 +100,19 @@ fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<V::BreakTy>
}
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref }, _) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
self.visit_trait(trait_ref)
}
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty.visit_with(self)?;
self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx()))
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
ty.visit_with(self)
}
ty::PredicateAtom::RegionOutlives(..) => ControlFlow::CONTINUE,
ty::PredicateAtom::ConstEvaluatable(..)
ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE,
ty::PredicateKind::ConstEvaluatable(..)
if self.def_id_visitor.tcx().features().const_evaluatable_checked =>
{
// FIXME(const_evaluatable_checked): If the constant used here depends on a

View File

@ -1153,7 +1153,7 @@ fn fold_opaque_ty(
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
for predicate in &bounds {
if let ty::PredicateAtom::Projection(projection) = predicate.skip_binders() {
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
if projection.ty.references_error() {
// No point on adding these obligations since there's a type error involved.
return ty_var;
@ -1251,18 +1251,18 @@ pub fn may_define_opaque_type(
traits::elaborate_predicates(tcx, predicates)
.filter_map(|obligation| {
debug!("required_region_bounds(obligation={:?})", obligation);
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Projection(..)
| ty::PredicateKind::Trait(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
// Search for a bound of the form `erased_self_ty
// : 'a`, but be wary of something like `for<'a>
// erased_self_ty : 'a` (we interpret a

View File

@ -414,9 +414,9 @@ fn add_user_pred(
let mut should_add_new = true;
user_computed_preds.retain(|&old_pred| {
if let (
ty::PredicateAtom::Trait(new_trait, _),
ty::PredicateAtom::Trait(old_trait, _),
) = (new_pred.skip_binders(), old_pred.skip_binders())
ty::PredicateKind::Trait(new_trait, _),
ty::PredicateKind::Trait(old_trait, _),
) = (new_pred.kind().skip_binder(), old_pred.kind().skip_binder())
{
if new_trait.def_id() == old_trait.def_id() {
let new_substs = new_trait.trait_ref.substs;
@ -633,16 +633,16 @@ fn evaluate_nested_obligations(
// We check this by calling is_of_param on the relevant types
// from the various possible predicates
let bound_predicate = predicate.bound_atom();
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(p, _) => {
ty::PredicateKind::Trait(p, _) => {
// Add this to `predicates` so that we end up calling `select`
// with it. If this predicate ends up being unimplemented,
// then `evaluate_predicates` will handle adding it the `ParamEnv`
// if possible.
predicates.push_back(bound_predicate.rebind(p));
}
ty::PredicateAtom::Projection(p) => {
ty::PredicateKind::Projection(p) => {
let p = bound_predicate.rebind(p);
debug!(
"evaluate_nested_obligations: examining projection predicate {:?}",
@ -772,13 +772,13 @@ fn evaluate_nested_obligations(
}
}
}
ty::PredicateAtom::RegionOutlives(binder) => {
ty::PredicateKind::RegionOutlives(binder) => {
let binder = bound_predicate.rebind(binder);
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
return false;
}
}
ty::PredicateAtom::TypeOutlives(binder) => {
ty::PredicateKind::TypeOutlives(binder) => {
let binder = bound_predicate.rebind(binder);
match (
binder.no_bound_vars(),
@ -801,7 +801,7 @@ fn evaluate_nested_obligations(
_ => {}
};
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
let evaluate = |c: &'tcx ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val {
match select.infcx().const_eval_resolve(

View File

@ -41,8 +41,8 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
// We are looking at a generic abstract constant.
Some(ct) => {
for pred in param_env.caller_bounds() {
match pred.skip_binders() {
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
match pred.kind().skip_binder() {
ty::PredicateKind::ConstEvaluatable(b_def, b_substs) => {
debug!(
"is_const_evaluatable: caller_bound={:?}, {:?}",
b_def, b_substs

View File

@ -256,9 +256,9 @@ fn report_selection_error(
return;
}
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
ty::PredicateKind::Trait(trait_predicate, _) => {
let trait_predicate = bound_predicate.rebind(trait_predicate);
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
@ -517,14 +517,14 @@ fn report_selection_error(
err
}
ty::PredicateAtom::Subtype(predicate) => {
ty::PredicateKind::Subtype(predicate) => {
// Errors for Subtype predicates show up as
// `FulfillmentErrorCode::CodeSubtypeError`,
// not selection error.
span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
}
ty::PredicateAtom::RegionOutlives(predicate) => {
ty::PredicateKind::RegionOutlives(predicate) => {
let predicate = bound_predicate.rebind(predicate);
let predicate = self.resolve_vars_if_possible(predicate);
let err = self
@ -541,7 +541,7 @@ fn report_selection_error(
)
}
ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => {
ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => {
let predicate = self.resolve_vars_if_possible(obligation.predicate);
struct_span_err!(
self.tcx.sess,
@ -552,12 +552,12 @@ fn report_selection_error(
)
}
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
ty::PredicateKind::ObjectSafe(trait_def_id) => {
let violations = self.tcx.object_safety_violations(trait_def_id);
report_object_safety_error(self.tcx, span, trait_def_id, violations)
}
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span =
self.tcx.sess.source_map().guess_head_span(
@ -617,7 +617,7 @@ fn report_selection_error(
return;
}
ty::PredicateAtom::WellFormed(ty) => {
ty::PredicateKind::WellFormed(ty) => {
if !self.tcx.sess.opts.debugging_opts.chalk {
// WF predicates cannot themselves make
// errors. They can only block due to
@ -635,7 +635,7 @@ fn report_selection_error(
}
}
ty::PredicateAtom::ConstEvaluatable(..) => {
ty::PredicateKind::ConstEvaluatable(..) => {
// Errors for `ConstEvaluatable` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
@ -646,7 +646,7 @@ fn report_selection_error(
)
}
ty::PredicateAtom::ConstEquate(..) => {
ty::PredicateKind::ConstEquate(..) => {
// Errors for `ConstEquate` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
@ -657,7 +657,7 @@ fn report_selection_error(
)
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => span_bug!(
ty::PredicateKind::TypeWellFormedFromEnv(..) => span_bug!(
span,
"TypeWellFormedFromEnv predicate should only exist in the environment"
),
@ -1069,9 +1069,9 @@ fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -
}
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
let bound_error = error.bound_atom();
let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) {
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
let bound_error = error.kind();
let (cond, error) = match (cond.kind().skip_binder(), bound_error.skip_binder()) {
(ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => {
(cond, bound_error.rebind(error))
}
_ => {
@ -1081,8 +1081,8 @@ fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -
};
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() {
let bound_predicate = obligation.predicate.kind();
if let ty::PredicateKind::Trait(implication, _) = bound_predicate.skip_binder() {
let error = error.to_poly_trait_ref();
let implication = bound_predicate.rebind(implication.trait_ref);
// FIXME: I'm just not taking associated types at all here.
@ -1162,8 +1162,8 @@ fn report_projection_error(
//
// this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message.
let bound_predicate = predicate.bound_atom();
if let ty::PredicateAtom::Projection(data) = bound_predicate.skip_binder() {
let bound_predicate = predicate.kind();
if let ty::PredicateKind::Projection(data) = bound_predicate.skip_binder() {
let mut selcx = SelectionContext::new(self);
let (data, _) = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
@ -1452,9 +1452,9 @@ fn maybe_report_ambiguity(
return;
}
let bound_predicate = predicate.bound_atom();
let bound_predicate = predicate.kind();
let mut err = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
ty::PredicateKind::Trait(data, _) => {
let trait_ref = bound_predicate.rebind(data.trait_ref);
debug!("trait_ref {:?}", trait_ref);
@ -1559,7 +1559,7 @@ fn maybe_report_ambiguity(
err
}
ty::PredicateAtom::WellFormed(arg) => {
ty::PredicateKind::WellFormed(arg) => {
// Same hacky approach as above to avoid deluging user
// with error messages.
if arg.references_error() || self.tcx.sess.has_errors() {
@ -1569,7 +1569,7 @@ fn maybe_report_ambiguity(
self.emit_inference_failure_err(body_id, span, arg, ErrorCode::E0282)
}
ty::PredicateAtom::Subtype(data) => {
ty::PredicateKind::Subtype(data) => {
if data.references_error() || self.tcx.sess.has_errors() {
// no need to overload user in such cases
return;
@ -1579,7 +1579,7 @@ fn maybe_report_ambiguity(
assert!(a.is_ty_var() && b.is_ty_var());
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282)
}
ty::PredicateAtom::Projection(data) => {
ty::PredicateKind::Projection(data) => {
let trait_ref = bound_predicate.rebind(data).to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.ty;
@ -1709,9 +1709,10 @@ fn suggest_unsized_bound_if_applicable(
obligation: &PredicateObligation<'tcx>,
) {
let (pred, item_def_id, span) =
match (obligation.predicate.skip_binders(), obligation.cause.code.peel_derives()) {
match (obligation.predicate.kind().skip_binder(), obligation.cause.code.peel_derives())
{
(
ty::PredicateAtom::Trait(pred, _),
ty::PredicateKind::Trait(pred, _),
&ObligationCauseCode::BindingObligation(item_def_id, span),
) => (pred, item_def_id, span),
_ => return,

View File

@ -1292,8 +1292,8 @@ fn maybe_note_obligation_cause_for_async_await(
// the type. The last generator (`outer_generator` below) has information about where the
// bound was introduced. At least one generator should be present for this diagnostic to be
// modified.
let (mut trait_ref, mut target_ty) = match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
_ => (None, None),
};
let mut generator = None;

View File

@ -345,12 +345,13 @@ fn progress_changed_obligations(
let infcx = self.selcx.infcx();
match *obligation.predicate.kind() {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
let binder = obligation.predicate.kind();
match binder.no_bound_vars() {
None => match binder.skip_binder() {
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
ty::PredicateAtom::Trait(trait_ref, _constness) => {
ty::PredicateKind::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(binder.rebind(trait_ref));
self.process_trait_obligation(
@ -359,7 +360,7 @@ fn progress_changed_obligations(
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::Projection(data) => {
ty::PredicateKind::Projection(data) => {
let project_obligation = obligation.with(binder.rebind(data));
self.process_projection_obligation(
@ -367,25 +368,25 @@ fn progress_changed_obligations(
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => {
let pred = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())),
]))
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
},
ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(data, _) => {
Some(pred) => match pred {
ty::PredicateKind::Trait(data, _) => {
let trait_obligation = obligation.with(Binder::dummy(data));
self.process_trait_obligation(
@ -395,14 +396,14 @@ fn progress_changed_obligations(
)
}
ty::PredicateAtom::RegionOutlives(data) => {
ty::PredicateKind::RegionOutlives(data) => {
match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
Ok(()) => ProcessResult::Changed(vec![]),
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
}
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
if self.register_region_obligations {
self.selcx.infcx().register_region_obligation_with_cause(
t_a,
@ -413,7 +414,7 @@ fn progress_changed_obligations(
ProcessResult::Changed(vec![])
}
ty::PredicateAtom::Projection(ref data) => {
ty::PredicateKind::Projection(ref data) => {
let project_obligation = obligation.with(Binder::dummy(*data));
self.process_projection_obligation(
@ -422,7 +423,7 @@ fn progress_changed_obligations(
)
}
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) {
ProcessResult::Error(CodeSelectionError(Unimplemented))
} else {
@ -430,7 +431,7 @@ fn progress_changed_obligations(
}
}
ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
@ -443,7 +444,7 @@ fn progress_changed_obligations(
}
}
ty::PredicateAtom::WellFormed(arg) => {
ty::PredicateKind::WellFormed(arg) => {
match wf::obligations(
self.selcx.infcx(),
obligation.param_env,
@ -461,7 +462,7 @@ fn progress_changed_obligations(
}
}
ty::PredicateAtom::Subtype(subtype) => {
ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate(
&obligation.cause,
obligation.param_env,
@ -487,7 +488,7 @@ fn progress_changed_obligations(
}
}
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
match const_evaluatable::is_const_evaluatable(
self.selcx.infcx(),
def_id,
@ -507,7 +508,7 @@ fn progress_changed_obligations(
}
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
debug!(?c1, ?c2, "equating consts");
if self.selcx.tcx().features().const_evaluatable_checked {
// FIXME: we probably should only try to unify abstract constants
@ -593,7 +594,7 @@ fn progress_changed_obligations(
}
}
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
},

View File

@ -324,7 +324,7 @@ pub fn normalize_param_env_or_error<'tcx>(
// TypeOutlives predicates - these are normally used by regionck.
let outlives_predicates: Vec<_> = predicates
.drain_filter(|predicate| {
matches!(predicate.skip_binders(), ty::PredicateAtom::TypeOutlives(..))
matches!(predicate.kind().skip_binder(), ty::PredicateKind::TypeOutlives(..))
})
.collect();

View File

@ -273,12 +273,12 @@ fn predicate_references_self(
) -> Option<Span> {
let self_ty = tcx.types.self_param;
let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into());
match predicate.skip_binders() {
ty::PredicateAtom::Trait(ref data, _) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ref data, _) => {
// In the case of a trait predicate, we can skip the "self" type.
if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
}
ty::PredicateAtom::Projection(ref data) => {
ty::PredicateKind::Projection(ref data) => {
// And similarly for projections. This should be redundant with
// the previous check because any projection should have a
// matching `Trait` predicate with the same inputs, but we do
@ -300,15 +300,15 @@ fn predicate_references_self(
None
}
}
ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::TypeOutlives(..)
| ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::TypeOutlives(..)
| ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
}
}
@ -328,20 +328,20 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let predicates = tcx.predicates_of(def_id);
let predicates = predicates.instantiate_identity(tcx).predicates;
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(ref trait_pred, _) => {
match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ref trait_pred, _) => {
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
}
ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::TypeOutlives(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => false,
ty::PredicateKind::Projection(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::TypeOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => false,
}
})
}
@ -843,7 +843,7 @@ fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
}
fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::PredicateAtom::ConstEvaluatable(def, substs) = pred.skip_binders() {
if let ty::PredicateKind::ConstEvaluatable(def, substs) = pred.kind().skip_binder() {
// FIXME(const_evaluatable_checked): We should probably deduplicate the logic for
// `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to
// take a `ty::Const` instead.

View File

@ -625,7 +625,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
.obligations
.iter()
.filter(|obligation| {
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
// We found a `T: Foo<X = U>` predicate, let's check
// if `U` references any unresolved type
@ -636,7 +636,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
// indirect obligations (e.g., we project to `?0`,
// but we have `T: Foo<X = ?1>` and `?1: Bar<X =
// ?0>`).
ty::PredicateAtom::Projection(data) => {
ty::PredicateKind::Projection(data) => {
infcx.unresolved_type_vars(&bound_predicate.rebind(data.ty)).is_some()
}
@ -917,8 +917,8 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx();
for predicate in env_predicates {
debug!(?predicate);
let bound_predicate = predicate.bound_atom();
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let bound_predicate = predicate.kind();
if let ty::PredicateKind::Projection(data) = predicate.kind().skip_binder() {
let data = bound_predicate.rebind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;

View File

@ -15,7 +15,7 @@ fn try_fast_path(
// `&T`, accounts for about 60% percentage of the predicates
// we have to prove. No need to canonicalize and all that for
// such cases.
if let ty::PredicateAtom::Trait(trait_ref, _) = key.value.predicate.skip_binders() {
if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind().skip_binder() {
if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
if trait_ref.def_id() == sized_def_id {
if trait_ref.self_ty().is_trivially_sized(tcx) {

View File

@ -432,7 +432,7 @@ fn confirm_object_candidate(
.predicates
.into_iter()
{
if let ty::PredicateAtom::Trait(..) = super_trait.skip_binders() {
if let ty::PredicateKind::Trait(..) = super_trait.kind().skip_binder() {
let normalized_super_trait = normalize_with_depth_to(
self,
obligation.param_env,
@ -641,7 +641,7 @@ fn confirm_closure_candidate(
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::PredicateAtom::ClosureKind(closure_def_id, substs, kind)
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
.to_predicate(self.tcx()),
));
}

View File

@ -454,16 +454,16 @@ fn evaluate_predicate_recursively<'o>(
}
let result = ensure_sufficient_stack(|| {
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(t, _) => {
ty::PredicateKind::Trait(t, _) => {
let t = bound_predicate.rebind(t);
debug_assert!(!t.has_escaping_bound_vars());
let obligation = obligation.with(t);
self.evaluate_trait_predicate_recursively(previous_stack, obligation)
}
ty::PredicateAtom::Subtype(p) => {
ty::PredicateKind::Subtype(p) => {
let p = bound_predicate.rebind(p);
// Does this code ever run?
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
@ -479,7 +479,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateAtom::WellFormed(arg) => match wf::obligations(
ty::PredicateKind::WellFormed(arg) => match wf::obligations(
self.infcx,
obligation.param_env,
obligation.cause.body_id,
@ -494,12 +494,12 @@ fn evaluate_predicate_recursively<'o>(
None => Ok(EvaluatedToAmbig),
},
ty::PredicateAtom::TypeOutlives(..) | ty::PredicateAtom::RegionOutlives(..) => {
ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => {
// We do not consider region relationships when evaluating trait matches.
Ok(EvaluatedToOkModuloRegions)
}
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
ty::PredicateKind::ObjectSafe(trait_def_id) => {
if self.tcx().is_object_safe(trait_def_id) {
Ok(EvaluatedToOk)
} else {
@ -507,7 +507,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateAtom::Projection(data) => {
ty::PredicateKind::Projection(data) => {
let data = bound_predicate.rebind(data);
let project_obligation = obligation.with(data);
match project::poly_project_and_unify_type(self, &project_obligation) {
@ -528,7 +528,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.infcx.closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
@ -541,7 +541,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
match const_evaluatable::is_const_evaluatable(
self.infcx,
def_id,
@ -555,7 +555,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");
let evaluate = |c: &'tcx ty::Const<'tcx>| {
@ -598,7 +598,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for chalk")
}
}
@ -845,8 +845,8 @@ pub fn coinductive_match<I>(&mut self, mut cycle: I) -> bool
}
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
let result = match predicate.skip_binders() {
ty::PredicateAtom::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
let result = match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
_ => false,
};
debug!(?predicate, ?result, "coinductive_predicate");
@ -1174,8 +1174,8 @@ fn match_projection_obligation_against_definition_bounds(
.iter()
.enumerate()
.filter_map(|(idx, bound)| {
let bound_predicate = bound.bound_atom();
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let bound_predicate = bound.kind();
if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() {
let bound = bound_predicate.rebind(pred.trait_ref);
if self.infcx.probe(|_| {
match self.match_normalize_trait_ref(

View File

@ -106,28 +106,28 @@ pub fn predicate_obligations<'a, 'tcx>(
};
// It's ok to skip the binder here because wf code is prepared for it
match predicate.skip_binders() {
ty::PredicateAtom::Trait(t, _) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(t, _) => {
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
}
ty::PredicateAtom::RegionOutlives(..) => {}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
ty::PredicateKind::RegionOutlives(..) => {}
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
wf.compute(ty.into());
}
ty::PredicateAtom::Projection(t) => {
ty::PredicateKind::Projection(t) => {
wf.compute_projection(t.projection_ty);
wf.compute(t.ty.into());
}
ty::PredicateAtom::WellFormed(arg) => {
ty::PredicateKind::WellFormed(arg) => {
wf.compute(arg);
}
ty::PredicateAtom::ObjectSafe(_) => {}
ty::PredicateAtom::ClosureKind(..) => {}
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
ty::PredicateKind::ObjectSafe(_) => {}
ty::PredicateKind::ClosureKind(..) => {}
ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
wf.compute(a.into());
wf.compute(b.into());
}
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
ty::PredicateKind::ConstEvaluatable(def, substs) => {
let obligations = wf.nominal_obligations(def.did, substs);
wf.out.extend(obligations);
@ -135,11 +135,11 @@ pub fn predicate_obligations<'a, 'tcx>(
wf.compute(arg);
}
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
wf.compute(c1.into());
wf.compute(c2.into());
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
}
@ -209,8 +209,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
};
// It is fine to skip the binder as we don't care about regions here.
match pred.skip_binders() {
ty::PredicateAtom::Projection(proj) => {
match pred.kind().skip_binder() {
ty::PredicateKind::Projection(proj) => {
// The obligation comes not from the current `impl` nor the `trait` being implemented,
// but rather from a "second order" obligation, where an associated type has a
// projection coming from another associated type. See
@ -225,7 +225,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
}
}
}
ty::PredicateAtom::Trait(pred, _) => {
ty::PredicateKind::Trait(pred, _) => {
// An associated item obligation born out of the `trait` failed to be met. An example
// can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
@ -343,7 +343,7 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo
new_cause,
depth,
param_env,
ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
)
}),
);
@ -393,7 +393,7 @@ fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) {
cause.clone(),
depth,
param_env,
ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
)
}),
);
@ -436,7 +436,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
let obligations = self.nominal_obligations(def.did, substs);
self.out.extend(obligations);
let predicate = ty::PredicateAtom::ConstEvaluatable(def, substs)
let predicate = ty::PredicateKind::ConstEvaluatable(def, substs)
.to_predicate(self.tcx());
let cause = self.cause(traits::MiscObligation);
self.out.push(traits::Obligation::with_depth(
@ -460,7 +460,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
cause,
self.recursion_depth,
self.param_env,
ty::PredicateAtom::WellFormed(resolved_constant.into())
ty::PredicateKind::WellFormed(resolved_constant.into())
.to_predicate(self.tcx()),
));
}
@ -547,7 +547,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
cause,
depth,
param_env,
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(rty, r))
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
.to_predicate(self.tcx()),
));
}
@ -637,7 +637,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
cause.clone(),
depth,
param_env,
ty::PredicateAtom::ObjectSafe(did).to_predicate(tcx),
ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
)
}));
}
@ -664,7 +664,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
cause,
self.recursion_depth,
param_env,
ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()),
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
));
} else {
// Yes, resolved, proceed with the result.

View File

@ -81,39 +81,36 @@ fn lower_into(
interner: &RustInterner<'tcx>,
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
let clauses = self.environment.into_iter().map(|predicate| {
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
predicate.bound_atom_with_opt_escaping(interner.tcx),
);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate.kind());
let consequence = match predicate {
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
}
ty::PredicateAtom::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv(
ty::PredicateKind::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv(
chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
),
ty::PredicateAtom::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
}),
),
ty::PredicateAtom::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
}),
),
ty::PredicateAtom::Projection(predicate) => chalk_ir::DomainGoal::Holds(
ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
),
ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
};
let value = chalk_ir::ProgramClauseImplication {
consequence,
@ -136,19 +133,16 @@ fn lower_into(
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
self.bound_atom_with_opt_escaping(interner.tcx),
);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => {
ty::PredicateKind::Trait(predicate, _) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
))
}
ty::PredicateAtom::RegionOutlives(predicate) => {
ty::PredicateKind::RegionOutlives(predicate) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
@ -156,7 +150,7 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
}),
))
}
ty::PredicateAtom::TypeOutlives(predicate) => {
ty::PredicateKind::TypeOutlives(predicate) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
@ -164,12 +158,12 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
}),
))
}
ty::PredicateAtom::Projection(predicate) => {
ty::PredicateKind::Projection(predicate) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
))
}
ty::PredicateAtom::WellFormed(arg) => match arg.unpack() {
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
GenericArgKind::Type(ty) => match ty.kind() {
// FIXME(chalk): In Chalk, a placeholder is WellFormed if it
// `FromEnv`. However, when we "lower" Params, we don't update
@ -189,7 +183,7 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
},
ty::PredicateAtom::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(t)),
),
@ -197,13 +191,13 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
//
// We can defer this, but ultimately we'll want to express
// some of these in terms of chalk operations.
ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal(
ty::PredicateKind::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal(
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))),
),
};
@ -573,38 +567,35 @@ fn lower_into(
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
self.bound_atom_with_opt_escaping(interner.tcx),
);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => {
ty::PredicateKind::Trait(predicate, _) => {
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
}
ty::PredicateAtom::RegionOutlives(predicate) => {
ty::PredicateKind::RegionOutlives(predicate) => {
Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
}))
}
ty::PredicateAtom::TypeOutlives(predicate) => {
ty::PredicateKind::TypeOutlives(predicate) => {
Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
}))
}
ty::PredicateAtom::Projection(predicate) => {
ty::PredicateKind::Projection(predicate) => {
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
}
ty::PredicateAtom::WellFormed(_ty) => None,
ty::PredicateKind::WellFormed(_ty) => None,
ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("unexpected predicate {}", &self)
}
};
@ -707,32 +698,29 @@ fn lower_into(
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
self.bound_atom_with_opt_escaping(interner.tcx),
);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
match predicate {
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
ty::PredicateKind::Trait(predicate, _) => Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::TraitBound(
predicate.trait_ref.lower_into(interner),
),
)),
ty::PredicateAtom::Projection(predicate) => Some(chalk_ir::Binders::new(
ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
)),
ty::PredicateAtom::TypeOutlives(_predicate) => None,
ty::PredicateAtom::WellFormed(_ty) => None,
ty::PredicateKind::TypeOutlives(_predicate) => None,
ty::PredicateKind::WellFormed(_ty) => None,
ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("unexpected predicate {}", &self)
}
}

View File

@ -94,27 +94,27 @@ fn compute_implied_outlives_bounds<'tcx>(
// region relationships.
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
assert!(!obligation.has_escaping_bound_vars());
match obligation.predicate.kind() {
&ty::PredicateKind::ForAll(..) => vec![],
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => vec![],
ty::PredicateAtom::WellFormed(arg) => {
match obligation.predicate.kind().no_bound_vars() {
None => vec![],
Some(pred) => match pred {
ty::PredicateKind::Trait(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => vec![],
ty::PredicateKind::WellFormed(arg) => {
wf_args.push(arg);
vec![]
}
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
let ty_a = infcx.resolve_vars_if_possible(ty_a);
let mut components = smallvec![];
tcx.push_outlives_components(ty_a, &mut components);

View File

@ -46,16 +46,16 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
}
fn not_outlives_predicate(p: &ty::Predicate<'tcx>) -> bool {
match p.skip_binders() {
ty::PredicateAtom::RegionOutlives(..) | ty::PredicateAtom::TypeOutlives(..) => false,
ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => true,
match p.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
ty::PredicateKind::Trait(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => true,
}
}

View File

@ -140,7 +140,7 @@ fn relate_mir_and_user_ty(
self.relate(self_ty, Variance::Invariant, impl_self_ty)?;
self.prove_predicate(
ty::PredicateAtom::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
);
}
@ -155,7 +155,7 @@ fn relate_mir_and_user_ty(
// them? This would only be relevant if some input
// type were ill-formed but did not appear in `ty`,
// which...could happen with normalization...
self.prove_predicate(ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()));
self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()));
Ok(())
}
}

View File

@ -5,7 +5,7 @@
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, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
};
use rustc_session::CrateDisambiguator;
use rustc_span::symbol::Symbol;
@ -378,8 +378,8 @@ enum NodeKind {
let input_clauses = inputs.into_iter().filter_map(|arg| {
match arg.unpack() {
GenericArgKind::Type(ty) => {
let binder = Binder::dummy(PredicateAtom::TypeWellFormedFromEnv(ty));
Some(tcx.mk_predicate(PredicateKind::ForAll(binder)))
let binder = Binder::dummy(PredicateKind::TypeWellFormedFromEnv(ty));
Some(tcx.mk_predicate(binder))
}
// FIXME(eddyb) no WF conditions from lifetimes?

View File

@ -1177,9 +1177,9 @@ trait here instead: `trait NewTrait: {} {{}}`",
obligation.predicate
);
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(pred, _) => {
ty::PredicateKind::Trait(pred, _) => {
let pred = bound_predicate.rebind(pred);
associated_types.entry(span).or_default().extend(
tcx.associated_items(pred.def_id())
@ -1188,7 +1188,7 @@ trait here instead: `trait NewTrait: {} {{}}`",
.map(|item| item.def_id),
);
}
ty::PredicateAtom::Projection(pred) => {
ty::PredicateKind::Projection(pred) => {
let pred = bound_predicate.rebind(pred);
// A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that.

View File

@ -544,9 +544,9 @@ pub(crate) fn opt_suggest_box_span(
self.infcx.instantiate_opaque_types(id, self.body_id, self.param_env, ty, span);
let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty();
for o in impl_trait_ret_ty.obligations {
match o.predicate.skip_binders_unchecked() {
ty::PredicateAtom::Trait(t, constness) => {
let pred = ty::PredicateAtom::Trait(
match o.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(t, constness) => {
let pred = ty::PredicateKind::Trait(
ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: t.def_id(),

View File

@ -192,9 +192,9 @@ fn deduce_expectations_from_obligations(
obligation.predicate
);
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders()
let bound_predicate = obligation.predicate.kind();
if let ty::PredicateKind::Projection(proj_predicate) =
obligation.predicate.kind().skip_binder()
{
// Given a Projection predicate, we can potentially infer
// the complete signature.
@ -622,8 +622,8 @@ fn deduce_future_output_from_obligations(&self, expr_def_id: DefId) -> Option<Ty
// where R is the return type we are expecting. This type `T`
// will be our output.
let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Projection(proj_predicate) = bound_predicate.skip_binder() {
let bound_predicate = obligation.predicate.kind();
if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() {
self.deduce_future_output_from_projection(
obligation.cause.span,
bound_predicate.rebind(proj_predicate),

View File

@ -583,9 +583,9 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
while !queue.is_empty() {
let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation);
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
let trait_pred = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_pred, _)
ty::PredicateKind::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>
{
if unsize_did == trait_pred.def_id() {

View File

@ -226,13 +226,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
// could be extended easily also to the other `Predicate`.
let predicate_matches_closure = |p: Predicate<'tcx>| {
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
let predicate = predicate.bound_atom();
let p = p.bound_atom();
let predicate = predicate.kind();
let p = p.kind();
match (predicate.skip_binder(), p.skip_binder()) {
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
(ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
}
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
}
_ => predicate == p,

View File

@ -542,7 +542,7 @@ pub fn register_wf_obligation(
self.register_predicate(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateAtom::WellFormed(arg).to_predicate(self.tcx),
ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx),
));
}
@ -764,21 +764,21 @@ pub(in super::super) fn obligations_for_self_ty<'b>(
.pending_obligations()
.into_iter()
.filter_map(move |obligation| {
let bound_predicate = obligation.predicate.bound_atom();
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Projection(data) => {
ty::PredicateKind::Projection(data) => {
Some((bound_predicate.rebind(data).to_poly_trait_ref(self.tcx), obligation))
}
ty::PredicateAtom::Trait(data, _) => {
ty::PredicateKind::Trait(data, _) => {
Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation))
}
ty::PredicateAtom::Subtype(..) => None,
ty::PredicateAtom::RegionOutlives(..) => None,
ty::PredicateAtom::TypeOutlives(..) => None,
ty::PredicateAtom::WellFormed(..) => None,
ty::PredicateAtom::ObjectSafe(..) => None,
ty::PredicateAtom::ConstEvaluatable(..) => None,
ty::PredicateAtom::ConstEquate(..) => None,
ty::PredicateKind::Subtype(..) => None,
ty::PredicateKind::RegionOutlives(..) => None,
ty::PredicateKind::TypeOutlives(..) => None,
ty::PredicateKind::WellFormed(..) => None,
ty::PredicateKind::ObjectSafe(..) => None,
ty::PredicateKind::ConstEvaluatable(..) => None,
ty::PredicateKind::ConstEquate(..) => None,
// N.B., this predicate is created by breaking down a
// `ClosureType: FnFoo()` predicate, where
// `ClosureType` represents some `Closure`. It can't
@ -787,8 +787,8 @@ pub(in super::super) fn obligations_for_self_ty<'b>(
// this closure yet; this is exactly why the other
// code is looking for a self type of a unresolved
// inference variable.
ty::PredicateAtom::ClosureKind(..) => None,
ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::ClosureKind(..) => None,
ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
}
})
.filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root))

View File

@ -923,8 +923,8 @@ fn point_at_arg_instead_of_call_if_possible(
continue;
}
if let ty::PredicateAtom::Trait(predicate, _) =
error.obligation.predicate.skip_binders()
if let ty::PredicateKind::Trait(predicate, _) =
error.obligation.predicate.kind().skip_binder()
{
// Collect the argument position for all arguments that could have caused this
// `FulfillmentError`.
@ -974,8 +974,8 @@ fn point_at_type_arg_instead_of_call_if_possible(
if let hir::ExprKind::Path(qpath) = &path.kind {
if let hir::QPath::Resolved(_, path) = &qpath {
for error in errors {
if let ty::PredicateAtom::Trait(predicate, _) =
error.obligation.predicate.skip_binders()
if let ty::PredicateKind::Trait(predicate, _) =
error.obligation.predicate.kind().skip_binder()
{
// If any of the type arguments in this path segment caused the
// `FullfillmentError`, point at its span (#61860).

View File

@ -194,8 +194,8 @@ fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredic
parent: None,
predicates: tcx.arena.alloc_from_iter(
self.param_env.caller_bounds().iter().filter_map(|predicate| {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _) if data.self_ty().is_param(index) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(data, _) if data.self_ty().is_param(index) => {
// HACK(eddyb) should get the original `Span`.
let span = tcx.def_span(def_id);
Some((predicate, span))

View File

@ -478,8 +478,8 @@ fn predicates_require_illegal_sized_bound(
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
// We don't care about regions here.
.filter_map(|obligation| match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => {
.filter_map(|obligation| match obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => {
let span = predicates
.predicates
.iter()

View File

@ -399,7 +399,7 @@ pub fn lookup_method_in_trait(
obligations.push(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateAtom::WellFormed(method_ty.into()).to_predicate(tcx),
ty::PredicateKind::WellFormed(method_ty.into()).to_predicate(tcx),
));
let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig };

View File

@ -795,9 +795,9 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
let bound_predicate = predicate.bound_atom();
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
ty::PredicateKind::Trait(trait_predicate, _) => {
match *trait_predicate.trait_ref.self_ty().kind() {
ty::Param(p) if p == param_ty => {
Some(bound_predicate.rebind(trait_predicate.trait_ref))
@ -805,16 +805,16 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
_ => None,
}
}
ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::TypeOutlives(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::TypeOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
}
});

View File

@ -582,8 +582,8 @@ macro_rules! report_function {
let mut collect_type_param_suggestions =
|self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| {
// We don't care about regions here, so it's fine to skip the binder here.
if let (ty::Param(_), ty::PredicateAtom::Trait(p, _)) =
(self_ty.kind(), parent_pred.skip_binders())
if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) =
(self_ty.kind(), parent_pred.kind().skip_binder())
{
if let ty::Adt(def, _) = p.trait_ref.self_ty().kind() {
let node = def.did.as_local().map(|def_id| {
@ -637,9 +637,9 @@ macro_rules! report_function {
}
};
let mut format_pred = |pred: ty::Predicate<'tcx>| {
let bound_predicate = pred.bound_atom();
let bound_predicate = pred.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Projection(pred) => {
ty::PredicateKind::Projection(pred) => {
let pred = bound_predicate.rebind(pred);
// `<Foo as Iterator>::Item = String`.
let trait_ref =
@ -658,7 +658,7 @@ macro_rules! report_function {
bound_span_label(trait_ref.self_ty(), &obligation, &quiet);
Some((obligation, trait_ref.self_ty()))
}
ty::PredicateAtom::Trait(poly_trait_ref, _) => {
ty::PredicateKind::Trait(poly_trait_ref, _) => {
let p = poly_trait_ref.trait_ref;
let self_ty = p.self_ty();
let path = p.print_only_trait_path();
@ -992,11 +992,11 @@ fn suggest_traits_to_import<'b>(
// implementing a trait would be legal but is rejected
// here).
unsatisfied_predicates.iter().all(|(p, _)| {
match p.skip_binders() {
match p.kind().skip_binder() {
// Hide traits if they are present in predicates as they can be fixed without
// having to implement them.
ty::PredicateAtom::Trait(t, _) => t.def_id() == info.def_id,
ty::PredicateAtom::Projection(p) => {
ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id,
ty::PredicateKind::Projection(p) => {
p.projection_ty.item_def_id == info.def_id
}
_ => false,

View File

@ -864,9 +864,9 @@ fn bounds_from_generic_predicates<'tcx>(
let mut projections = vec![];
for (predicate, _) in predicates.predicates {
debug!("predicate {:?}", predicate);
let bound_predicate = predicate.bound_atom();
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
ty::PredicateKind::Trait(trait_predicate, _) => {
let entry = types.entry(trait_predicate.self_ty()).or_default();
let def_id = trait_predicate.def_id();
if Some(def_id) != tcx.lang_items().sized_trait() {
@ -875,7 +875,7 @@ fn bounds_from_generic_predicates<'tcx>(
entry.push(trait_predicate.def_id());
}
}
ty::PredicateAtom::Projection(projection_pred) => {
ty::PredicateKind::Projection(projection_pred) => {
projections.push(bound_predicate.rebind(projection_pred));
}
_ => {}

View File

@ -532,7 +532,7 @@ fn check_type_defn<'tcx, F>(
fcx.register_predicate(traits::Obligation::new(
cause,
fcx.param_env,
ty::PredicateAtom::ConstEvaluatable(
ty::PredicateKind::ConstEvaluatable(
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
discr_substs,
)

View File

@ -562,8 +562,8 @@ fn type_param_predicates(
let extra_predicates = extend.into_iter().chain(
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
.into_iter()
.filter(|(predicate, _)| match predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _) => data.self_ty().is_param(index),
.filter(|(predicate, _)| match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index),
_ => false,
}),
);
@ -1027,7 +1027,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
// which will, in turn, reach indirect supertraits.
for &(pred, span) in superbounds {
debug!("superbound: {:?}", pred);
if let ty::PredicateAtom::Trait(bound, _) = pred.skip_binders() {
if let ty::PredicateKind::Trait(bound, _) = pred.kind().skip_binder() {
tcx.at(span).super_predicates_of(bound.def_id());
}
}
@ -1946,13 +1946,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
} else {
let span = bound_pred.bounded_ty.span;
let re_root_empty = tcx.lifetimes.re_root_empty;
let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
let predicate = ty::Binder::bind(ty::PredicateKind::TypeOutlives(
ty::OutlivesPredicate(ty, re_root_empty),
));
predicates.insert((
predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll),
span,
));
predicates.insert((predicate.to_predicate(tcx), span));
}
}
@ -1993,10 +1990,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
hir::GenericBound::Outlives(lifetime) => {
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
predicates.insert((
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
ty::Binder::bind(ty::PredicateKind::TypeOutlives(
ty::OutlivesPredicate(ty, region),
))
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
.to_predicate(tcx),
lifetime.span,
));
}
@ -2013,7 +2010,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
}
_ => bug!(),
};
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
let pred = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(icx.tcx);
(pred, span)
@ -2078,7 +2075,7 @@ fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val {
let span = self.tcx.hir().span(c.hir_id);
self.preds.insert((
ty::PredicateAtom::ConstEvaluatable(def, substs).to_predicate(self.tcx),
ty::PredicateKind::ConstEvaluatable(def, substs).to_predicate(self.tcx),
span,
));
}
@ -2097,7 +2094,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TyAliasVisitor<'a, 'tcx> {
fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val {
self.preds.insert((
ty::PredicateAtom::ConstEvaluatable(def, substs).to_predicate(self.tcx),
ty::PredicateKind::ConstEvaluatable(def, substs).to_predicate(self.tcx),
self.span,
));
}
@ -2183,12 +2180,12 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
.predicates
.iter()
.copied()
.filter(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()),
ty::PredicateAtom::Projection(proj) => {
.filter(|(pred, _)| match pred.kind().skip_binder() {
ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()),
ty::PredicateKind::Projection(proj) => {
!is_assoc_item_ty(proj.projection_ty.self_ty())
}
ty::PredicateAtom::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
ty::PredicateKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
_ => true,
})
.collect();
@ -2217,7 +2214,8 @@ fn projection_ty_from_predicates(
let (ty_def_id, item_def_id) = key;
let mut projection_ty = None;
for (predicate, _) in tcx.predicates_of(ty_def_id).predicates {
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder()
{
if item_def_id == projection_predicate.projection_ty.item_def_id {
projection_ty = Some(projection_predicate.projection_ty);
break;
@ -2264,7 +2262,7 @@ fn predicates_from_bound<'tcx>(
}
hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
let pred = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
.to_predicate(astconv.tcx());
vec![(pred, lifetime.span)]
}

View File

@ -36,13 +36,14 @@ fn associated_type_bounds<'tcx>(
let trait_def_id = tcx.associated_item(assoc_item_def_id).container.id();
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());
let bounds_from_parent =
trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => tr.self_ty() == item_ty,
ty::PredicateAtom::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
ty::PredicateAtom::TypeOutlives(outlives) => outlives.0 == item_ty,
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
match pred.kind().skip_binder() {
ty::PredicateKind::Trait(tr, _) => tr.self_ty() == item_ty,
ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty,
_ => false,
});
}
});
let all_bounds = tcx
.arena

View File

@ -183,7 +183,8 @@ pub fn setup_constraining_predicates<'tcx>(
for j in i..predicates.len() {
// Note that we don't have to care about binders here,
// as the impl trait ref never contains any late-bound regions.
if let ty::PredicateAtom::Projection(projection) = predicates[j].0.skip_binders() {
if let ty::PredicateKind::Projection(projection) = predicates[j].0.kind().skip_binder()
{
// Special case: watch out for some kind of sneaky attempt
// to project out an associated type defined by this very
// trait.

View File

@ -198,7 +198,7 @@ fn unconstrained_parent_impl_substs<'tcx>(
// the functions in `cgp` add the constrained parameters to a list of
// unconstrained parameters.
for (predicate, _) in impl_generic_predicates.predicates.iter() {
if let ty::PredicateAtom::Projection(proj) = predicate.skip_binders() {
if let ty::PredicateKind::Projection(proj) = predicate.kind().skip_binder() {
let projection_ty = proj.projection_ty;
let projected_ty = proj.ty;
@ -360,13 +360,13 @@ fn check_predicates<'tcx>(
fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, span: Span) {
debug!("can_specialize_on(predicate = {:?})", predicate);
match predicate.skip_binders() {
match predicate.kind().skip_binder() {
// Global predicates are either always true or always false, so we
// are fine to specialize on.
_ if predicate.is_global() => (),
// We allow specializing on explicitly marked traits with no associated
// items.
ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
if !matches!(
trait_predicate_kind(tcx, predicate),
Some(TraitSpecializationKind::Marker)
@ -393,20 +393,20 @@ fn trait_predicate_kind<'tcx>(
tcx: TyCtxt<'tcx>,
predicate: ty::Predicate<'tcx>,
) -> Option<TraitSpecializationKind> {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
Some(tcx.trait_def(pred.def_id()).specialization_kind)
}
ty::PredicateAtom::Trait(_, hir::Constness::Const)
| ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::Projection(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
ty::PredicateKind::Trait(_, hir::Constness::Const)
| ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::Projection(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
}
}

View File

@ -29,8 +29,8 @@ pub fn explicit_predicates_of(
// process predicates and convert to `RequiredPredicates` entry, see below
for &(predicate, span) in predicates.predicates {
match predicate.skip_binders() {
ty::PredicateAtom::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
insert_outlives_predicate(
tcx,
(*ty).into(),
@ -40,7 +40,7 @@ pub fn explicit_predicates_of(
)
}
ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
insert_outlives_predicate(
tcx,
(*reg1).into(),
@ -50,15 +50,15 @@ pub fn explicit_predicates_of(
)
}
ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => (),
ty::PredicateKind::Trait(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => (),
}
}

View File

@ -30,13 +30,9 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
let mut pred: Vec<String> = predicates
.iter()
.map(|(out_pred, _)| match out_pred.kind() {
ty::PredicateKind::Atom(ty::PredicateAtom::RegionOutlives(p)) => {
p.to_string()
}
ty::PredicateKind::Atom(ty::PredicateAtom::TypeOutlives(p)) => {
p.to_string()
}
.map(|(out_pred, _)| match out_pred.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(p) => p.to_string(),
ty::PredicateKind::TypeOutlives(p) => p.to_string(),
err => bug!("unexpected predicate {:?}", err),
})
.collect();
@ -89,12 +85,12 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|(ty::OutlivesPredicate(kind1, region2), &span)| {
match kind1.unpack() {
GenericArgKind::Type(ty1) => Some((
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
.to_predicate(tcx),
span,
)),
GenericArgKind::Lifetime(region1) => Some((
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
region1, region2,
))
.to_predicate(tcx),

View File

@ -313,12 +313,12 @@ fn extract_for_generics(
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> FxHashSet<GenericParamDef> {
let bound_predicate = pred.bound_atom();
let bound_predicate = pred.kind();
let regions = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(poly_trait_pred, _) => {
ty::PredicateKind::Trait(poly_trait_pred, _) => {
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))
}
ty::PredicateAtom::Projection(poly_proj_pred) => {
ty::PredicateKind::Projection(poly_proj_pred) => {
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred))
}
_ => return FxHashSet::default(),
@ -463,8 +463,8 @@ fn param_env_to_generics(
.iter()
.filter(|p| {
!orig_bounds.contains(p)
|| match p.skip_binders() {
ty::PredicateAtom::Trait(pred, _) => pred.def_id() == sized_trait,
|| match p.kind().skip_binder() {
ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
_ => false,
}
})

View File

@ -465,20 +465,20 @@ fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
let bound_predicate = self.bound_atom();
let bound_predicate = self.kind();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)),
ty::PredicateAtom::RegionOutlives(pred) => pred.clean(cx),
ty::PredicateAtom::TypeOutlives(pred) => pred.clean(cx),
ty::PredicateAtom::Projection(pred) => Some(pred.clean(cx)),
ty::PredicateKind::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)),
ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx),
ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx),
ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)),
ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => panic!("not user writable"),
ty::PredicateKind::Subtype(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => panic!("not user writable"),
}
}
}
@ -743,19 +743,19 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
.flat_map(|(p, _)| {
let mut projection = None;
let param_idx = (|| {
let bound_p = p.bound_atom();
let bound_p = p.kind();
match bound_p.skip_binder() {
ty::PredicateAtom::Trait(pred, _constness) => {
ty::PredicateKind::Trait(pred, _constness) => {
if let ty::Param(param) = pred.self_ty().kind() {
return Some(param.index);
}
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
if let ty::Param(param) = ty.kind() {
return Some(param.index);
}
}
ty::PredicateAtom::Projection(p) => {
ty::PredicateKind::Projection(p) => {
if let ty::Param(param) = p.projection_ty.self_ty().kind() {
projection = Some(bound_p.rebind(p));
return Some(param.index);
@ -1684,14 +1684,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
let mut bounds = bounds
.iter()
.filter_map(|bound| {
// Note: The substs of opaque types can contain unbound variables,
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
let bound_predicate = bound.bound_atom_with_opt_escaping(cx.tcx);
let bound_predicate = bound.kind();
let trait_ref = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(tr, _constness) => {
ty::PredicateKind::Trait(tr, _constness) => {
bound_predicate.rebind(tr.trait_ref)
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
if let Some(r) = reg.clean(cx) {
regions.push(GenericBound::Outlives(r));
}
@ -1710,8 +1708,8 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
let bounds: Vec<_> = bounds
.iter()
.filter_map(|bound| {
if let ty::PredicateAtom::Projection(proj) =
bound.bound_atom_with_opt_escaping(cx.tcx).skip_binder()
if let ty::PredicateKind::Projection(proj) =
bound.kind().skip_binder()
{
if proj.projection_ty.trait_ref(cx.tcx)
== trait_ref.skip_binder()

View File

@ -129,7 +129,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId)
.predicates
.iter()
.filter_map(|(pred, _)| {
if let ty::PredicateAtom::Trait(pred, _) = pred.skip_binders() {
if let ty::PredicateKind::Trait(pred, _) = pred.kind().skip_binder() {
if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None }
} else {
None

View File

@ -1,4 +1,4 @@
error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))`
error: cannot specialize on `Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,)))`
--> $DIR/repeated_projection_type.rs:19:1
|
LL | / impl<I, V: Id<This = (I,)>> X for V {

View File

@ -4,7 +4,7 @@
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@ -97,7 +97,7 @@ fn check_fn(
&obligation,
);
if let Trait(trait_pred, _) =
obligation.predicate.skip_binders()
obligation.predicate.kind().skip_binder()
{
db.note(&format!(
"`{}` doesn't implement `{}`",

View File

@ -1697,7 +1697,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
if let ty::Opaque(def_id, _) = *ret_ty.kind() {
// one of the associated types must be Self
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
// walk the associated type and check for Self
if contains_ty(projection_predicate.ty, self_ty) {
return;

View File

@ -115,13 +115,11 @@ fn check_fn(
.filter(|p| !p.is_global())
.filter_map(|obligation| {
// Note that we do not want to deal with qualified predicates here.
if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
if pred.def_id() == sized_trait {
return None;
}
Some(pred)
} else {
None
match obligation.predicate.kind().no_bound_vars() {
Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => {
Some(pred)
},
_ => None,
}
})
.collect::<Vec<_>>();

View File

@ -4,7 +4,7 @@
use rustc_hir::{Expr, ExprKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate};
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{BytePos, Span};
@ -42,7 +42,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
let mut preds = Vec::new();
for (pred, _) in generics.predicates {
if_chain! {
if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders();
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder();
let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred));
if let Some(trait_def_id) = trait_id;
if trait_def_id == trait_pred.trait_ref.def_id;
@ -60,7 +60,7 @@ fn get_projection_pred<'tcx>(
pred: TraitPredicate<'tcx>,
) -> Option<ProjectionPredicate<'tcx>> {
generics.predicates.iter().find_map(|(proj_pred, _)| {
if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() {
if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() {
let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred));
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
return Some(projection_pred);

View File

@ -1470,7 +1470,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
ty::Opaque(ref def_id, _) => {
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() {
if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() {
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
return true;
}

View File

@ -19,18 +19,18 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult {
loop {
let predicates = tcx.predicates_of(current);
for (predicate, _) in predicates.predicates {
match predicate.skip_binders() {
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::Projection(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
ty::PredicateAtom::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
ty::PredicateAtom::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
ty::PredicateAtom::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
ty::PredicateAtom::Trait(pred, _) => {
match predicate.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::Projection(_)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
ty::PredicateKind::Trait(pred, _) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}