1
Fork 0

introduce PredicateAtom

This commit is contained in:
Bastian Kauschke 2020-07-09 00:35:55 +02:00
parent 52af82bdb9
commit d8cf8ba5f7
54 changed files with 803 additions and 850 deletions

View file

@ -530,11 +530,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
let predicate = match k1.unpack() {
GenericArgKind::Lifetime(r1) => {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Type(t1) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Const(..) => {
@ -665,7 +665,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
self.obligations.push(Obligation {
cause: self.cause.clone(),
param_env: self.param_env,
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
predicate: ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(sup, sub))
.to_predicate(self.infcx.tcx),
recursion_depth: 0,
});

View file

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

View file

@ -6,23 +6,29 @@ pub mod verify;
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>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
debug!("explicit_outlives_bounds()");
param_env.caller_bounds().into_iter().filter_map(move |predicate| match predicate.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(..) => None,
ty::PredicateKind::RegionOutlives(ref data) => data
.no_bound_vars()
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
param_env
.caller_bounds()
.into_iter()
.map(ty::Predicate::skip_binders)
.filter(TypeFoldable::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(..) => None,
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
}
})
}

View file

@ -100,7 +100,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
self.fields.obligations.push(Obligation::new(
self.fields.trace.cause.clone(),
self.fields.param_env,
ty::PredicateKind::Subtype(ty::SubtypePredicate {
ty::PredicateAtom::Subtype(ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
b,

View file

@ -15,16 +15,7 @@ pub fn anonymize_predicate<'tcx>(
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
tcx.reuse_or_mk_predicate(pred, new)
}
ty::PredicateKind::Trait(_, _)
| ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::Projection(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::ClosureKind(_, _, _)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::ConstEvaluatable(_, _)
| ty::PredicateKind::ConstEquate(_, _) => pred,
ty::PredicateKind::Atom(_) => pred,
}
}
@ -137,11 +128,8 @@ impl Elaborator<'tcx> {
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
ty::PredicateKind::Trait(data, _) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _) => {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());
@ -162,36 +150,36 @@ impl Elaborator<'tcx> {
self.stack.extend(obligations);
}
ty::PredicateKind::WellFormed(..) => {
ty::PredicateAtom::WellFormed(..) => {
// Currently, we do not elaborate WF predicates,
// although we easily could.
}
ty::PredicateKind::ObjectSafe(..) => {
ty::PredicateAtom::ObjectSafe(..) => {
// Currently, we do not elaborate object-safe
// predicates.
}
ty::PredicateKind::Subtype(..) => {
ty::PredicateAtom::Subtype(..) => {
// Currently, we do not "elaborate" predicates like `X <: Y`,
// though conceivably we might.
}
ty::PredicateKind::Projection(..) => {
ty::PredicateAtom::Projection(..) => {
// Nothing to elaborate in a projection predicate.
}
ty::PredicateKind::ClosureKind(..) => {
ty::PredicateAtom::ClosureKind(..) => {
// Nothing to elaborate when waiting for a closure's kind to be inferred.
}
ty::PredicateKind::ConstEvaluatable(..) => {
ty::PredicateAtom::ConstEvaluatable(..) => {
// Currently, we do not elaborate const-evaluatable
// predicates.
}
ty::PredicateKind::ConstEquate(..) => {
ty::PredicateAtom::ConstEquate(..) => {
// Currently, we do not elaborate const-equate
// predicates.
}
ty::PredicateKind::RegionOutlives(..) => {
ty::PredicateAtom::RegionOutlives(..) => {
// Nothing to elaborate from `'a: 'b`.
}
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
ty::PredicateAtom::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
@ -221,7 +209,7 @@ impl Elaborator<'tcx> {
if r.is_late_bound() {
None
} else {
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
r, r_min,
)))
}
@ -229,7 +217,7 @@ impl Elaborator<'tcx> {
Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name);
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
Some(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
ty, r_min,
)))
}

View file

@ -1202,7 +1202,7 @@ declare_lint_pass!(
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::PredicateKind::*;
use rustc_middle::ty::PredicateAtom::*;
if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
@ -1210,7 +1210,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
for &(predicate, span) in predicates.predicates {
// We don't actually look inside of the predicate,
// so it is safe to skip this binder here.
let predicate_kind_name = match predicate.ignore_quantifiers().skip_binder().kind() {
let predicate_kind_name = match predicate.skip_binders() {
Trait(..) => "Trait",
TypeOutlives(..) |
RegionOutlives(..) => "Lifetime",
@ -1225,7 +1225,6 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
Subtype(..) |
ConstEvaluatable(..) |
ConstEquate(..) => continue,
ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
};
if predicate.is_global() {
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {
@ -1500,8 +1499,8 @@ impl ExplicitOutlivesRequirements {
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
.filter_map(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
_ => None,
},
@ -1516,8 +1515,8 @@ impl ExplicitOutlivesRequirements {
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
.filter_map(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
a.is_param(index).then_some(b)
}
_ => None,

View file

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

View file

@ -208,39 +208,6 @@ impl FlagComputation {
fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
match kind {
ty::PredicateKind::Trait(trait_pred, _constness) => {
self.add_substs(trait_pred.trait_ref.substs);
}
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
self.add_region(a);
self.add_region(b);
}
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
self.add_ty(ty);
self.add_region(region);
}
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
self.add_ty(a);
self.add_ty(b);
}
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
self.add_projection_ty(projection_ty);
self.add_ty(ty);
}
ty::PredicateKind::WellFormed(arg) => {
self.add_substs(slice::from_ref(arg));
}
ty::PredicateKind::ObjectSafe(_def_id) => {}
ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
self.add_substs(substs);
}
ty::PredicateKind::ConstEvaluatable(_def_id, substs) => {
self.add_substs(substs);
}
ty::PredicateKind::ConstEquate(expected, found) => {
self.add_const(expected);
self.add_const(found);
}
ty::PredicateKind::ForAll(binder) => {
let mut computation = FlagComputation::new();
@ -248,6 +215,41 @@ impl FlagComputation {
self.add_bound_computation(computation);
}
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(trait_pred, _constness) => {
self.add_substs(trait_pred.trait_ref.substs);
}
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
self.add_region(a);
self.add_region(b);
}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
self.add_ty(ty);
self.add_region(region);
}
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
self.add_ty(a);
self.add_ty(b);
}
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
self.add_projection_ty(projection_ty);
self.add_ty(ty);
}
ty::PredicateAtom::WellFormed(arg) => {
self.add_substs(slice::from_ref(&arg));
}
ty::PredicateAtom::ObjectSafe(_def_id) => {}
ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
self.add_substs(substs);
}
ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
self.add_substs(substs);
}
ty::PredicateAtom::ConstEquate(expected, found) => {
self.add_const(expected);
self.add_const(found);
}
},
}
}

View file

@ -1018,7 +1018,7 @@ crate struct PredicateInner<'tcx> {
}
#[cfg(target_arch = "x86_64")]
static_assert_size!(PredicateInner<'_>, 40);
static_assert_size!(PredicateInner<'_>, 48);
#[derive(Clone, Copy, Lift)]
pub struct Predicate<'tcx> {
@ -1049,46 +1049,35 @@ impl<'tcx> Predicate<'tcx> {
&self.inner.kind
}
/// Skips `PredicateKind::ForAll`.
pub fn ignore_quantifiers(self) -> Binder<Predicate<'tcx>> {
/// Returns the inner `PredicateAtom`.
///
/// 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,
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::RegionOutlives(..) => Binder::dummy(self),
&PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
&ty::PredicateKind::Atom(atom) => atom,
}
}
/// Skips `PredicateKind::ForAll`, while allowing for unbound variables.
/// Returns the inner `PredicateAtom`.
///
/// This method requires the `TyCtxt` as it has to shift the unbound variables
/// outwards.
///
/// Do not use this method if you may end up just skipping the binder, as this
/// would leave the unbound variables at an incorrect binding level.
pub fn ignore_quantifiers_with_unbound_vars(
self,
tcx: TyCtxt<'tcx>,
) -> Binder<Predicate<'tcx>> {
/// Note that this method does not check if predicate has unbound variables,
/// rebinding the returned atom potentially 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,
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::RegionOutlives(..) => Binder::wrap_nonbinding(tcx, self),
&PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
&ty::PredicateKind::Atom(atom) => atom,
}
}
pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder.map_bound(|inner| match inner.kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpect forall"),
&ty::PredicateKind::Atom(atom) => atom,
}),
&ty::PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
}
}
@ -1124,6 +1113,15 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
pub enum PredicateKind<'tcx> {
/// `for<'a>: ...`
ForAll(Binder<Predicate<'tcx>>),
Atom(PredicateAtom<'tcx>),
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[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.
@ -1162,9 +1160,6 @@ pub enum PredicateKind<'tcx> {
/// Constants must be equal. The first component is the const that is expected.
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
/// `for<'a>: ...`
ForAll(Binder<Predicate<'tcx>>),
}
/// The crate outlives map is computed during typeck and contains the
@ -1252,9 +1247,13 @@ impl<'tcx> Predicate<'tcx> {
// from the substitution and the value being substituted into, and
// this trick achieves that).
let substs = trait_ref.skip_binder().substs;
let pred = self.ignore_quantifiers().skip_binder();
let pred = self.skip_binders();
let new = pred.subst(tcx, substs);
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
if new != pred {
new.to_predicate(tcx).potentially_quantified(tcx, PredicateKind::ForAll)
} else {
self
}
}
}
@ -1379,9 +1378,16 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
}
}
impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
#[inline(always)]
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
tcx.mk_predicate(ty::PredicateKind::Atom(*self))
}
}
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
.to_predicate(tcx)
}
}
@ -1399,94 +1405,88 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
if let Some(pred) = self.value.no_bound_vars() {
ty::PredicateKind::Trait(pred, self.constness)
ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
} else {
ty::PredicateKind::ForAll(
self.value.map_bound(|pred| {
ty::PredicateKind::Trait(pred, self.constness).to_predicate(tcx)
ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
}),
)
}
.to_predicate(tcx)
}
}
}
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
if let Some(outlives) = self.no_bound_vars() {
PredicateKind::RegionOutlives(outlives)
PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
} else {
ty::PredicateKind::ForAll(
self.map_bound(|outlives| {
PredicateKind::RegionOutlives(outlives).to_predicate(tcx)
PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
}),
)
}
.to_predicate(tcx)
}
}
}
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
if let Some(outlives) = self.no_bound_vars() {
PredicateKind::TypeOutlives(outlives)
PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)
} else {
ty::PredicateKind::ForAll(
self.map_bound(|outlives| PredicateKind::TypeOutlives(outlives).to_predicate(tcx)),
self.map_bound(|outlives| PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)),
)
}
.to_predicate(tcx)
}
}
}
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
if let Some(proj) = self.no_bound_vars() {
PredicateKind::Projection(proj)
PredicateAtom::Projection(proj).to_predicate(tcx)
} else {
ty::PredicateKind::ForAll(
self.map_bound(|proj| PredicateKind::Projection(proj).to_predicate(tcx)),
self.map_bound(|proj| PredicateAtom::Projection(proj).to_predicate(tcx)),
)
}
.to_predicate(tcx)
}
}
}
impl<'tcx> Predicate<'tcx> {
pub fn to_opt_poly_trait_ref(self) -> Option<PolyTraitRef<'tcx>> {
self.ignore_quantifiers()
.map_bound(|pred| match pred.kind() {
&PredicateKind::Trait(ref t, _) => Some(t.trait_ref),
PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
| PredicateKind::WellFormed(..)
| PredicateKind::ObjectSafe(..)
| PredicateKind::ClosureKind(..)
| PredicateKind::TypeOutlives(..)
| PredicateKind::ConstEvaluatable(..)
| PredicateKind::ConstEquate(..) => None,
PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
})
.transpose()
match self.skip_binders() {
PredicateAtom::Trait(t, _) => Some(ty::Binder::bind(t.trait_ref)),
PredicateAtom::Projection(..)
| PredicateAtom::Subtype(..)
| PredicateAtom::RegionOutlives(..)
| PredicateAtom::WellFormed(..)
| PredicateAtom::ObjectSafe(..)
| PredicateAtom::ClosureKind(..)
| PredicateAtom::TypeOutlives(..)
| PredicateAtom::ConstEvaluatable(..)
| PredicateAtom::ConstEquate(..) => None,
}
}
pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
self.ignore_quantifiers()
.map_bound(|pred| match pred.kind() {
&PredicateKind::TypeOutlives(data) => Some(data),
PredicateKind::Trait(..)
| PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
| PredicateKind::WellFormed(..)
| PredicateKind::ObjectSafe(..)
| PredicateKind::ClosureKind(..)
| PredicateKind::ConstEvaluatable(..)
| PredicateKind::ConstEquate(..) => None,
PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
})
.transpose()
match self.skip_binders() {
PredicateAtom::TypeOutlives(data) => Some(ty::Binder::bind(data)),
PredicateAtom::Trait(..)
| PredicateAtom::Projection(..)
| PredicateAtom::Subtype(..)
| PredicateAtom::RegionOutlives(..)
| PredicateAtom::WellFormed(..)
| PredicateAtom::ObjectSafe(..)
| PredicateAtom::ClosureKind(..)
| PredicateAtom::ConstEvaluatable(..)
| PredicateAtom::ConstEquate(..) => None,
}
}
}

View file

@ -576,10 +576,8 @@ pub trait PrettyPrinter<'tcx>:
// may contain unbound variables. We therefore do this manually.
//
// FIXME(lcnr): Find out why exactly this is the case :)
if let ty::PredicateKind::Trait(pred, _) = predicate
.ignore_quantifiers_with_unbound_vars(self.tcx())
.skip_binder()
.kind()
if let ty::PredicateAtom::Trait(pred, _) =
predicate.bound_atom(self.tcx()).skip_binder()
{
let trait_ref = ty::Binder::bind(pred.trait_ref);
// Don't print +Sized, but rather +?Sized if absent.
@ -2015,39 +2013,41 @@ define_print_and_forward_display! {
ty::Predicate<'tcx> {
match self.kind() {
&ty::PredicateKind::Trait(ref data, constness) => {
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(ref data, constness) => {
if let hir::Constness::Const = constness {
p!(write("const "));
}
p!(print(data))
}
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), write(" well-formed")),
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
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), write(" well-formed")),
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
p!(write("the trait `"),
print_def_path(trait_def_id, &[]),
write("` is object-safe"))
}
&ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
p!(write("the closure `"),
print_value_path(closure_def_id, &[]),
write("` implements the trait `{}`", kind))
}
&ty::PredicateKind::ConstEvaluatable(def, substs) => {
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
p!(write("the constant `"),
print_value_path(def.did, substs),
write("` can be evaluated"))
}
ty::PredicateKind::ConstEquate(c1, c2) => {
ty::PredicateAtom::ConstEquate(c1, c2) => {
p!(write("the constant `"),
print(c1),
write("` equals `"),
print(c2),
write("`"))
}
}
ty::PredicateKind::ForAll(binder) => {
p!(print(binder))
}

View file

@ -226,28 +226,36 @@ impl fmt::Debug for ty::Predicate<'tcx> {
impl fmt::Debug for ty::PredicateKind<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::PredicateKind::Trait(ref a, constness) => {
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) => {
if let hir::Constness::Const = constness {
write!(f, "const ")?;
}
a.fmt(f)
}
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) => {
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) => {
write!(f, "ObjectSafe({:?})", trait_def_id)
}
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
}
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
ty::PredicateAtom::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
}
}
}
@ -479,37 +487,46 @@ 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::Trait(ref data, constness) => {
tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness))
}
ty::PredicateKind::Subtype(ref data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
ty::PredicateKind::RegionOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
}
ty::PredicateKind::TypeOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
}
ty::PredicateKind::Projection(ref data) => {
tcx.lift(data).map(ty::PredicateKind::Projection)
}
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::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
})
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
Some(ty::PredicateKind::ObjectSafe(trait_def_id))
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs))
}
ty::PredicateKind::ConstEquate(c1, c2) => {
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
}
ty::PredicateKind::ForAll(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::ForAll)
}
ty::PredicateKind::Atom(ref 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(ref data, constness) => {
tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness))
}
ty::PredicateAtom::Subtype(ref data) => tcx.lift(data).map(ty::PredicateAtom::Subtype),
ty::PredicateAtom::RegionOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateAtom::RegionOutlives)
}
ty::PredicateAtom::TypeOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateAtom::TypeOutlives)
}
ty::PredicateAtom::Projection(ref data) => {
tcx.lift(data).map(ty::PredicateAtom::Projection)
}
ty::PredicateAtom::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateAtom::WellFormed),
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
tcx.lift(&closure_substs).map(|closure_substs| {
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind)
})
}
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
Some(ty::PredicateAtom::ObjectSafe(trait_def_id))
}
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
tcx.lift(&substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs))
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
}
}
}
}

View file

@ -589,8 +589,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut found = false;
for predicate in bounds.predicates {
if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
predicate.ignore_quantifiers().skip_binder().kind()
if let ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_, r)) =
predicate.skip_binders()
{
if let ty::RegionKind::ReStatic = r {
found = true;

View file

@ -1021,7 +1021,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
self.prove_predicate(
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
ty::PredicateAtom::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
Locations::All(span),
ConstraintCategory::TypeAnnotation,
);
@ -1273,7 +1273,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
obligations.obligations.push(traits::Obligation::new(
ObligationCause::dummy(),
param_env,
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
ty::PredicateAtom::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
));
obligations.add(
infcx
@ -1617,7 +1617,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.check_call_dest(body, term, &sig, destination, term_location);
self.prove_predicates(
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
sig.inputs_and_output.iter().map(|ty| ty::PredicateAtom::WellFormed(ty.into())),
term_location.to_locations(),
ConstraintCategory::Boring,
);
@ -2702,7 +2702,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
category: ConstraintCategory,
) {
self.prove_predicates(
Some(ty::PredicateKind::Trait(
Some(ty::PredicateAtom::Trait(
ty::TraitPredicate { trait_ref },
hir::Constness::NotConst,
)),

View file

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

View file

@ -85,23 +85,18 @@ where
}
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> bool {
match predicate.kind() {
&ty::PredicateKind::ForAll(pred) => {
// This visitor does not care about bound regions as we only
// look at `DefId`s.
self.visit_predicate(pred.skip_binder())
}
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref }, _) => {
self.visit_trait(trait_ref)
}
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty.visit_with(self)
|| self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx()))
}
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
ty.visit_with(self)
}
ty::PredicateKind::RegionOutlives(..) => false,
ty::PredicateAtom::RegionOutlives(..) => false,
_ => bug!("unexpected predicate: {:?}", predicate),
}
}

View file

@ -1154,9 +1154,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
for predicate in &bounds.predicates {
if let ty::PredicateKind::Projection(projection) =
predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Projection(projection) = predicate.skip_binders() {
if projection.ty.references_error() {
// No point on adding these obligations since there's a type error involved.
return ty_var;
@ -1254,18 +1252,17 @@ crate fn required_region_bounds(
traits::elaborate_predicates(tcx, predicates)
.filter_map(|obligation| {
debug!("required_region_bounds(obligation={:?})", obligation);
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
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(..) => None,
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", obligation),
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
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(..) => None,
ty::PredicateAtom::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

@ -415,12 +415,10 @@ impl AutoTraitFinder<'tcx> {
let mut should_add_new = true;
user_computed_preds.retain(|&old_pred| {
if let (
ty::PredicateKind::Trait(new_trait, _),
ty::PredicateKind::Trait(old_trait, _),
) = (
new_pred.ignore_quantifiers().skip_binder().kind(),
old_pred.ignore_quantifiers().skip_binder().kind(),
) {
ty::PredicateAtom::Trait(new_trait, _),
ty::PredicateAtom::Trait(old_trait, _),
) = (new_pred.skip_binders(), old_pred.skip_binders())
{
if new_trait.def_id() == old_trait.def_id() {
let new_substs = new_trait.trait_ref.substs;
let old_substs = old_trait.trait_ref.substs;
@ -639,8 +637,8 @@ impl AutoTraitFinder<'tcx> {
// We check this by calling is_of_param on the relevant types
// from the various possible predicates
match predicate.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(p, _) => {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(p, _) => {
if self.is_param_no_infer(p.trait_ref.substs)
&& !only_projections
&& is_new_pred
@ -649,7 +647,7 @@ impl AutoTraitFinder<'tcx> {
}
predicates.push_back(ty::Binder::bind(p));
}
&ty::PredicateKind::Projection(p) => {
ty::PredicateAtom::Projection(p) => {
let p = ty::Binder::bind(p);
debug!(
"evaluate_nested_obligations: examining projection predicate {:?}",
@ -775,13 +773,13 @@ impl AutoTraitFinder<'tcx> {
}
}
}
&ty::PredicateKind::RegionOutlives(binder) => {
ty::PredicateAtom::RegionOutlives(binder) => {
let binder = ty::Binder::bind(binder);
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
return false;
}
}
&ty::PredicateKind::TypeOutlives(binder) => {
ty::PredicateAtom::TypeOutlives(binder) => {
let binder = ty::Binder::bind(binder);
match (
binder.no_bound_vars(),

View file

@ -256,11 +256,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::Trait(trait_predicate, _) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
let trait_predicate = ty::Binder::bind(trait_predicate);
let trait_predicate = self.resolve_vars_if_possible(&trait_predicate);
@ -525,14 +522,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
err
}
ty::PredicateKind::Subtype(predicate) => {
ty::PredicateAtom::Subtype(predicate) => {
// Errors for Subtype predicates show up as
// `FulfillmentErrorCode::CodeSubtypeError`,
// not selection error.
span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
}
&ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let predicate = self.resolve_vars_if_possible(&predicate);
let err = self
@ -549,7 +546,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
}
ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => {
ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => {
let predicate = self.resolve_vars_if_possible(&obligation.predicate);
struct_span_err!(
self.tcx.sess,
@ -560,12 +557,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
}
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
ty::PredicateAtom::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::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateAtom::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(
@ -624,7 +621,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
ty::PredicateKind::WellFormed(ty) => {
ty::PredicateAtom::WellFormed(ty) => {
if !self.tcx.sess.opts.debugging_opts.chalk {
// WF predicates cannot themselves make
// errors. They can only block due to
@ -642,7 +639,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
ty::PredicateKind::ConstEvaluatable(..) => {
ty::PredicateAtom::ConstEvaluatable(..) => {
// Errors for `ConstEvaluatable` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
@ -653,7 +650,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
}
ty::PredicateKind::ConstEquate(..) => {
ty::PredicateAtom::ConstEquate(..) => {
// Errors for `ConstEquate` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
@ -1090,11 +1087,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
let (cond, error) = match (
cond.ignore_quantifiers().skip_binder().kind(),
error.ignore_quantifiers().skip_binder().kind(),
) {
(ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(error, _)) => {
let (cond, error) = match (cond.skip_binders(), error.skip_binders()) {
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
(cond, ty::Binder::bind(error))
}
_ => {
@ -1104,9 +1098,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
};
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
if let &ty::PredicateKind::Trait(implication, _) =
obligation.predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Trait(implication, _) = obligation.predicate.skip_binders() {
let error = error.to_poly_trait_ref();
let implication = ty::Binder::bind(implication).to_poly_trait_ref();
// FIXME: I'm just not taking associated types at all here.
@ -1186,9 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
//
// this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message.
if let &ty::PredicateKind::Projection(data) =
predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let mut selcx = SelectionContext::new(self);
let (data, _) = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
@ -1480,8 +1470,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
let mut err = match predicate.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(data, _) => {
let mut err = match predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _) => {
let trait_ref = ty::Binder::bind(data.trait_ref);
let self_ty = trait_ref.skip_binder().self_ty();
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
@ -1580,7 +1570,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
err
}
ty::PredicateKind::WellFormed(arg) => {
ty::PredicateAtom::WellFormed(arg) => {
// Same hacky approach as above to avoid deluging user
// with error messages.
if arg.references_error() || self.tcx.sess.has_errors() {
@ -1600,17 +1590,17 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
ty::PredicateKind::Subtype(data) => {
ty::PredicateAtom::Subtype(data) => {
if data.references_error() || self.tcx.sess.has_errors() {
// no need to overload user in such cases
return;
}
let &SubtypePredicate { a_is_expected: _, a, b } = data;
let SubtypePredicate { a_is_expected: _, a, b } = data;
// both must be type variables, or the other would've been instantiated
assert!(a.is_ty_var() && b.is_ty_var());
self.need_type_info_err(body_id, span, a, ErrorCode::E0282)
}
&ty::PredicateKind::Projection(data) => {
ty::PredicateAtom::Projection(data) => {
let trait_ref = ty::Binder::bind(data).to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.ty;
@ -1733,12 +1723,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'tcx>,
obligation: &PredicateObligation<'tcx>,
) {
let (pred, item_def_id, span) = match (
obligation.predicate.ignore_quantifiers().skip_binder().kind(),
obligation.cause.code.peel_derives(),
) {
let (pred, item_def_id, span) =
match (obligation.predicate.skip_binders(), obligation.cause.code.peel_derives()) {
(
ty::PredicateKind::Trait(pred, _),
ty::PredicateAtom::Trait(pred, _),
&ObligationCauseCode::BindingObligation(item_def_id, span),
) => (pred, item_def_id, span),
_ => return,

View file

@ -1299,9 +1299,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// 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.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
let (mut trait_ref, mut target_ty) = match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
_ => (None, None),
};
let mut generator = None;

View file

@ -320,11 +320,13 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
match obligation.predicate.kind() {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected forall"),
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
ty::PredicateKind::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(Binder::bind(*trait_ref));
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(Binder::bind(trait_ref));
self.process_trait_obligation(
obligation,
@ -332,28 +334,29 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
&mut pending_obligation.stalled_on,
)
}
ty::PredicateKind::Projection(projection) => {
let project_obligation = obligation.with(Binder::bind(*projection));
ty::PredicateAtom::Projection(projection) => {
let project_obligation = obligation.with(Binder::bind(projection));
self.process_projection_obligation(
project_obligation,
&mut pending_obligation.stalled_on,
)
}
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::ForAll(_) => {
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
}
},
ty::PredicateKind::Trait(ref data, _) => {
},
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(ref data, _) => {
let trait_obligation = obligation.with(Binder::dummy(*data));
self.process_trait_obligation(
@ -363,14 +366,14 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
)
}
&ty::PredicateKind::RegionOutlives(data) => {
ty::PredicateAtom::RegionOutlives(data) => {
match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
Ok(()) => ProcessResult::Changed(vec![]),
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
}
}
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
if self.register_region_obligations {
self.selcx.infcx().register_region_obligation_with_cause(
t_a,
@ -381,7 +384,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
ProcessResult::Changed(vec![])
}
ty::PredicateKind::Projection(ref data) => {
ty::PredicateAtom::Projection(ref data) => {
let project_obligation = obligation.with(Binder::dummy(*data));
self.process_projection_obligation(
@ -390,7 +393,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
)
}
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) {
ProcessResult::Error(CodeSelectionError(Unimplemented))
} else {
@ -398,7 +401,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
@ -411,7 +414,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKind::WellFormed(arg) => {
ty::PredicateAtom::WellFormed(arg) => {
match wf::obligations(
self.selcx.infcx(),
obligation.param_env,
@ -428,7 +431,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKind::Subtype(subtype) => {
ty::PredicateAtom::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate(
&obligation.cause,
obligation.param_env,
@ -454,7 +457,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
match self.selcx.infcx().const_eval_resolve(
obligation.param_env,
def_id,
@ -467,7 +470,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
ty::PredicateKind::ConstEquate(c1, c2) => {
ty::PredicateAtom::ConstEquate(c1, c2) => {
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
let stalled_on = &mut pending_obligation.stalled_on;
@ -491,8 +494,6 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
);
Err(ErrorHandled::TooGeneric)
}
Err(err) => Err(err),
}
} else {
Ok(c)
}
@ -507,27 +508,32 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
.eq(c1, c2)
{
Ok(_) => ProcessResult::Changed(vec![]),
Err(err) => {
ProcessResult::Error(FulfillmentErrorCode::CodeConstEquateError(
Err(err) => ProcessResult::Error(
FulfillmentErrorCode::CodeConstEquateError(
ExpectedFound::new(true, c1, c2),
err,
))
}
),
),
}
}
(Err(ErrorHandled::Reported(ErrorReported)), _)
| (_, Err(ErrorHandled::Reported(ErrorReported))) => ProcessResult::Error(
CodeSelectionError(ConstEvalFailure(ErrorHandled::Reported(ErrorReported))),
),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
| (_, Err(ErrorHandled::Reported(ErrorReported))) => {
ProcessResult::Error(CodeSelectionError(ConstEvalFailure(
ErrorHandled::Reported(ErrorReported),
)))
}
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
span_bug!(
obligation.cause.span(self.selcx.tcx()),
"ConstEquate: const_eval_resolve returned an unexpected error"
),
)
}
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
ProcessResult::Unchanged
}
}
}
},
}
}

View file

@ -328,8 +328,8 @@ pub fn normalize_param_env_or_error<'tcx>(
// This works fairly well because trait matching does not actually care about param-env
// TypeOutlives predicates - these are normally used by regionck.
let outlives_predicates: Vec<_> = predicates
.drain_filter(|predicate| match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::TypeOutlives(..) => true,
.drain_filter(|predicate| match predicate.skip_binders() {
ty::PredicateAtom::TypeOutlives(..) => true,
_ => false,
})
.collect();

View file

@ -245,12 +245,12 @@ fn predicates_reference_self(
.iter()
.map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
.filter_map(|(predicate, &sp)| {
match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(ref data, _) => {
match predicate.skip_binders() {
ty::PredicateAtom::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::PredicateKind::Projection(ref data) => {
ty::PredicateAtom::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
@ -269,15 +269,14 @@ fn predicates_reference_self(
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(..) => None,
ty::PredicateKind::ForAll(..) => bug!("unexpected predicate: {:?}", predicate),
ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::TypeOutlives(..)
| ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => None,
}
})
.collect()
@ -299,22 +298,19 @@ 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.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(ref trait_pred, _) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(ref trait_pred, _) => {
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
}
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(..) => false,
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
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(..) => false,
}
})
}

View file

@ -665,7 +665,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
.obligations
.iter()
.filter(|obligation| {
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
match obligation.predicate.skip_binders() {
// We found a `T: Foo<X = U>` predicate, let's check
// if `U` references any unresolved type
// variables. In principle, we only care if this
@ -675,7 +675,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::PredicateKind::Projection(data) => {
ty::PredicateAtom::Projection(data) => {
infcx.unresolved_type_vars(&ty::Binder::bind(data.ty)).is_some()
}
@ -933,9 +933,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx();
for predicate in env_predicates {
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
if let &ty::PredicateKind::Projection(data) =
predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let data = ty::Binder::bind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
@ -1227,15 +1225,13 @@ fn confirm_object_candidate<'cx, 'tcx>(
// select only those projections that are actually projecting an
// item with the correct name
let env_predicates = env_predicates.filter_map(|o| {
match o.predicate.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Projection(data)
let env_predicates = env_predicates.filter_map(|o| match o.predicate.skip_binders() {
ty::PredicateAtom::Projection(data)
if data.projection_ty.item_def_id == obligation.predicate.item_def_id =>
{
Some(ty::Binder::bind(data))
}
_ => None,
}
});
// select those with a relevant trait-ref

View file

@ -15,9 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
// `&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::PredicateKind::Trait(trait_ref, _) =
key.value.predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Trait(trait_ref, _) = key.value.predicate.skip_binders() {
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

@ -532,7 +532,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
ty::PredicateAtom::ClosureKind(closure_def_id, substs, kind)
.to_predicate(self.tcx()),
));
}

View file

@ -408,18 +408,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
None => self.check_recursion_limit(&obligation, &obligation)?,
}
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::Trait(t, _) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(t, _) => {
let t = ty::Binder::bind(t);
debug_assert!(!t.has_escaping_bound_vars());
let obligation = obligation.with(t);
self.evaluate_trait_predicate_recursively(previous_stack, obligation)
}
&ty::PredicateKind::Subtype(p) => {
ty::PredicateAtom::Subtype(p) => {
let p = ty::Binder::bind(p);
// Does this code ever run?
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
@ -435,7 +432,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
&ty::PredicateKind::WellFormed(arg) => match wf::obligations(
ty::PredicateAtom::WellFormed(arg) => match wf::obligations(
self.infcx,
obligation.param_env,
obligation.cause.body_id,
@ -449,12 +446,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
None => Ok(EvaluatedToAmbig),
},
ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => {
ty::PredicateAtom::TypeOutlives(..) | ty::PredicateAtom::RegionOutlives(..) => {
// We do not consider region relationships when evaluating trait matches.
Ok(EvaluatedToOkModuloRegions)
}
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
if self.tcx().is_object_safe(trait_def_id) {
Ok(EvaluatedToOk)
} else {
@ -462,7 +459,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
&ty::PredicateKind::Projection(data) => {
ty::PredicateAtom::Projection(data) => {
let data = ty::Binder::bind(data);
let project_obligation = obligation.with(data);
match project::poly_project_and_unify_type(self, &project_obligation) {
@ -484,7 +481,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
match self.infcx.closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
@ -497,7 +494,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
match self.tcx().const_eval_resolve(
obligation.param_env,
def_id,
@ -511,7 +508,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
ty::PredicateKind::ConstEquate(c1, c2) => {
ty::PredicateAtom::ConstEquate(c1, c2) => {
debug!("evaluate_predicate_recursively: equating consts c1={:?} c2={:?}", c1, c2);
let evaluate = |c: &'tcx ty::Const<'tcx>| {
@ -792,8 +789,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
let result = match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
let result = match predicate.skip_binders() {
ty::PredicateAtom::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
_ => false,
};
debug!("coinductive_predicate({:?}) = {:?}", predicate, result);
@ -1301,9 +1298,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
};
let matching_bound = predicates.iter().find_map(|bound| {
if let ty::PredicateKind::Trait(pred, _) =
bound.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Trait(pred, _) = bound.skip_binders() {
let bound = ty::Binder::bind(pred.trait_ref);
if self.infcx.probe(|_| {
self.match_projection(obligation, bound, placeholder_trait_predicate.trait_ref)

View file

@ -98,27 +98,28 @@ pub fn predicate_obligations<'a, 'tcx>(
// It's ok to skip the binder here because wf code is prepared for it
return predicate_obligations(infcx, param_env, body_id, binder.skip_binder(), span);
}
ty::PredicateKind::Trait(t, _) => {
&ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(t, _) => {
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
}
ty::PredicateKind::RegionOutlives(..) => {}
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
ty::PredicateAtom::RegionOutlives(..) => {}
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
wf.compute(ty.into());
}
ty::PredicateKind::Projection(t) => {
ty::PredicateAtom::Projection(t) => {
wf.compute_projection(t.projection_ty);
wf.compute(t.ty.into());
}
&ty::PredicateKind::WellFormed(arg) => {
ty::PredicateAtom::WellFormed(arg) => {
wf.compute(arg);
}
ty::PredicateKind::ObjectSafe(_) => {}
ty::PredicateKind::ClosureKind(..) => {}
&ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
ty::PredicateAtom::ObjectSafe(_) => {}
ty::PredicateAtom::ClosureKind(..) => {}
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
wf.compute(a.into());
wf.compute(b.into());
}
&ty::PredicateKind::ConstEvaluatable(def, substs) => {
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
let obligations = wf.nominal_obligations(def.did, substs);
wf.out.extend(obligations);
@ -126,10 +127,11 @@ pub fn predicate_obligations<'a, 'tcx>(
wf.compute(arg);
}
}
&ty::PredicateKind::ConstEquate(c1, c2) => {
ty::PredicateAtom::ConstEquate(c1, c2) => {
wf.compute(c1.into());
wf.compute(c2.into());
}
},
}
wf.normalize()
@ -196,8 +198,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.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Projection(proj) => {
match pred.skip_binders() {
ty::PredicateAtom::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
@ -212,7 +214,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
}
}
}
ty::PredicateKind::Trait(pred, _) => {
ty::PredicateAtom::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);
@ -317,7 +319,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
traits::Obligation::new(
new_cause,
param_env,
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
)
}),
);
@ -374,7 +376,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let obligations = self.nominal_obligations(def.did, substs);
self.out.extend(obligations);
let predicate = ty::PredicateKind::ConstEvaluatable(def, substs)
let predicate = ty::PredicateAtom::ConstEvaluatable(def, substs)
.to_predicate(self.tcx());
let cause = self.cause(traits::MiscObligation);
self.out.push(traits::Obligation::new(
@ -396,7 +398,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.push(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateKind::WellFormed(resolved_constant.into())
ty::PredicateAtom::WellFormed(resolved_constant.into())
.to_predicate(self.tcx()),
));
}
@ -482,7 +484,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.push(traits::Obligation::new(
cause,
param_env,
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(rty, r))
.to_predicate(self.tcx()),
));
}
@ -573,7 +575,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
traits::Obligation::new(
cause.clone(),
param_env,
ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
ty::PredicateAtom::ObjectSafe(did).to_predicate(tcx),
)
}));
}
@ -599,7 +601,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.push(traits::Obligation::new(
cause,
param_env,
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()),
));
} else {
// Yes, resolved, proceed with the result.

View file

@ -79,13 +79,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
let clauses = self.environment.into_iter().filter_map(|clause| match clause {
ChalkEnvironmentClause::Predicate(predicate) => {
// FIXME(chalk): forall
match predicate
.ignore_quantifiers_with_unbound_vars(interner.tcx)
.skip_binder()
.kind()
{
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
&ty::PredicateKind::Trait(predicate, _) => {
match predicate.bound_atom(interner.tcx).skip_binder() {
ty::PredicateAtom::Trait(predicate, _) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -106,7 +101,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
.intern(interner),
)
}
&ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -131,8 +126,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
)
}
// FIXME(chalk): need to add TypeOutlives
ty::PredicateKind::TypeOutlives(_) => None,
&ty::PredicateKind::Projection(predicate) => {
ty::PredicateAtom::TypeOutlives(_) => None,
ty::PredicateAtom::Projection(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -153,12 +148,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
.intern(interner),
)
}
ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => {
ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
bug!("unexpected predicate {}", predicate)
}
}
@ -191,12 +186,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
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>> {
// FIXME(chalk): forall
match self.ignore_quantifiers_with_unbound_vars(interner.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
&ty::PredicateKind::Trait(predicate, _) => {
match self.bound_atom(interner.tcx).skip_binder() {
ty::PredicateAtom::Trait(predicate, _) => {
ty::Binder::bind(predicate).lower_into(interner)
}
&ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -216,13 +210,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
)
}
// FIXME(chalk): TypeOutlives
ty::PredicateKind::TypeOutlives(_predicate) => {
ty::PredicateAtom::TypeOutlives(_predicate) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
}
&ty::PredicateKind::Projection(predicate) => {
ty::PredicateAtom::Projection(predicate) => {
ty::Binder::bind(predicate).lower_into(interner)
}
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
ty::PredicateAtom::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
@ -252,18 +246,18 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
},
ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(*t)),
ty::PredicateAtom::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(t)),
),
// FIXME(chalk): other predicates
//
// We can defer this, but ultimately we'll want to express
// some of these in terms of chalk operations.
ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => {
ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
}
}
@ -561,9 +555,8 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
interner: &RustInterner<'tcx>,
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
// FIXME(chalk): forall
match self.ignore_quantifiers_with_unbound_vars(interner.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
&ty::PredicateKind::Trait(predicate, _) => {
match self.bound_atom(interner.tcx).skip_binder() {
ty::PredicateAtom::Trait(predicate, _) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -573,7 +566,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
))
}
&ty::PredicateKind::RegionOutlives(predicate) => {
ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
@ -586,15 +579,15 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
}),
))
}
ty::PredicateKind::TypeOutlives(_predicate) => None,
ty::PredicateKind::Projection(_predicate) => None,
ty::PredicateKind::WellFormed(_ty) => None,
ty::PredicateAtom::TypeOutlives(_predicate) => None,
ty::PredicateAtom::Projection(_predicate) => None,
ty::PredicateAtom::WellFormed(_ty) => None,
ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
}
}
}

View file

@ -95,29 +95,31 @@ fn compute_implied_outlives_bounds<'tcx>(
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::Trait(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => vec![],
&ty::PredicateKind::WellFormed(arg) => {
&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(..) => vec![],
ty::PredicateAtom::WellFormed(arg) => {
wf_args.push(arg);
vec![]
}
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
}
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
ty::PredicateAtom::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);
implied_bounds_from_components(r_b, components)
}
},
}
}));
}

View file

@ -40,16 +40,15 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
}
fn not_outlives_predicate(p: &ty::Predicate<'tcx>) -> bool {
match p.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", p),
ty::PredicateKind::Trait(..)
| ty::PredicateKind::Projection(..)
| ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => true,
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(..) => true,
}
}

View file

@ -140,7 +140,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
self.relate(self_ty, Variance::Invariant, impl_self_ty)?;
self.prove_predicate(
ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
ty::PredicateAtom::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
);
}
@ -155,7 +155,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
// 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::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()));
self.prove_predicate(ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()));
Ok(())
}
}

View file

@ -392,22 +392,22 @@ fn associated_type_projection_predicates(
let predicates = item_predicates.filter_map(|obligation| {
let pred = obligation.predicate;
match pred.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(tr, _) => {
match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => {
if let ty::Projection(p) = tr.self_ty().kind {
if p == assoc_item_ty {
return Some(pred);
}
}
}
ty::PredicateKind::Projection(proj) => {
ty::PredicateAtom::Projection(proj) => {
if let ty::Projection(p) = proj.projection_ty.self_ty().kind {
if p == assoc_item_ty {
return Some(pred);
}
}
}
ty::PredicateKind::TypeOutlives(outlives) => {
ty::PredicateAtom::TypeOutlives(outlives) => {
if let ty::Projection(p) = outlives.0.kind {
if p == assoc_item_ty {
return Some(pred);
@ -443,15 +443,15 @@ fn opaque_type_projection_predicates(
let filtered_predicates = predicates.filter_map(|obligation| {
let pred = obligation.predicate;
match pred.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(tr, _) => {
match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => {
if let ty::Opaque(opaque_def_id, opaque_substs) = tr.self_ty().kind {
if opaque_def_id == def_id && opaque_substs == substs {
return Some(pred);
}
}
}
ty::PredicateKind::Projection(proj) => {
ty::PredicateAtom::Projection(proj) => {
if let ty::Opaque(opaque_def_id, opaque_substs) = proj.projection_ty.self_ty().kind
{
if opaque_def_id == def_id && opaque_substs == substs {
@ -459,7 +459,7 @@ fn opaque_type_projection_predicates(
}
}
}
ty::PredicateKind::TypeOutlives(outlives) => {
ty::PredicateAtom::TypeOutlives(outlives) => {
if let ty::Opaque(opaque_def_id, opaque_substs) = outlives.0.kind {
if opaque_def_id == def_id && opaque_substs == substs {
return Some(pred);
@ -470,7 +470,7 @@ fn opaque_type_projection_predicates(
}
}
// These can come from elaborating other predicates
ty::PredicateKind::RegionOutlives(_) => return None,
ty::PredicateAtom::RegionOutlives(_) => return None,
_ => {}
}
tcx.sess.delay_span_bug(

View file

@ -1706,8 +1706,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
obligation.predicate
);
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(pred, _) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(pred, _) => {
let pred = ty::Binder::bind(pred);
associated_types.entry(span).or_default().extend(
tcx.associated_items(pred.def_id())
@ -1716,7 +1716,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.map(|item| item.def_id),
);
}
&ty::PredicateKind::Projection(pred) => {
ty::PredicateAtom::Projection(pred) => {
let pred = ty::Binder::bind(pred);
// A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that.

View file

@ -206,8 +206,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
obligation.predicate
);
if let &ty::PredicateKind::Projection(proj_predicate) =
obligation.predicate.ignore_quantifiers().skip_binder().kind()
if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders()
{
// Given a Projection predicate, we can potentially infer
// the complete signature.
@ -631,8 +631,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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)| {
if let &ty::PredicateKind::Projection(proj_predicate) =
obligation.predicate.ignore_quantifiers().skip_binder().kind()
if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders()
{
self.deduce_future_output_from_projection(
obligation.cause.span,

View file

@ -582,8 +582,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
while !queue.is_empty() {
let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation);
let trait_pred = match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(trait_pred, _)
let trait_pred = match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>
{
if unsize_did == trait_pred.def_id() {

View file

@ -226,14 +226,11 @@ 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);
match (
predicate.ignore_quantifiers().skip_binder().kind(),
p.ignore_quantifiers().skip_binder().kind(),
) {
(&ty::PredicateKind::Trait(a, _), &ty::PredicateKind::Trait(b, _)) => {
match (predicate.skip_binders(), p.skip_binders()) {
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
}
(&ty::PredicateKind::Projection(a), &ty::PredicateKind::Projection(b)) => {
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
}
_ => predicate == p,

View file

@ -448,24 +448,21 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
// We don't care about regions here.
.filter_map(|obligation| {
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(trait_pred, _)
if trait_pred.def_id() == sized_def_id =>
{
let span =
predicates
.filter_map(|obligation| match obligation.predicate.skip_binders() {
ty::PredicateAtom::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => {
let span = predicates
.predicates
.iter()
.zip(predicates.spans.iter())
.find_map(|(p, span)| {
.find_map(
|(p, span)| {
if *p == obligation.predicate { Some(*span) } else { None }
})
},
)
.unwrap_or(rustc_span::DUMMY_SP);
Some((trait_pred, span))
}
_ => None,
}
})
.find_map(|(trait_pred, span)| match trait_pred.self_ty().kind {
ty::Dynamic(..) => Some(span),

View file

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

View file

@ -798,24 +798,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| match predicate
.kind()
let bounds = self.param_env.caller_bounds().iter().map(ty::Predicate::skip_binders).filter_map(|predicate| match predicate
{
ty::PredicateKind::Trait(ref trait_predicate, _) => {
match trait_predicate.skip_binder().trait_ref.self_ty().kind {
ty::Param(ref p) if *p == param_ty => Some(trait_predicate.to_poly_trait_ref()),
ty::PredicateAtom::Trait(trait_predicate, _) => {
match trait_predicate.trait_ref.self_ty().kind {
ty::Param(ref p) if *p == param_ty => Some(ty::Binder::bind(trait_predicate.trait_ref)),
_ => 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(..) => 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(..) => None,
});
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {

View file

@ -576,10 +576,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this is kind of ugly.
|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::PredicateKind::Trait(p, _)) = (
&self_ty.kind,
parent_pred.ignore_quantifiers().skip_binder().kind(),
) {
if let (ty::Param(_), ty::PredicateAtom::Trait(p, _)) =
(&self_ty.kind, parent_pred.skip_binders())
{
if let ty::Adt(def, _) = p.trait_ref.self_ty().kind {
let node = def.did.as_local().map(|def_id| {
self.tcx.hir().get(self.tcx.hir().as_local_hir_id(def_id))
@ -631,8 +630,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
let mut format_pred = |pred: ty::Predicate<'tcx>| {
match pred.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Projection(pred) => {
match pred.skip_binders() {
ty::PredicateAtom::Projection(pred) => {
let pred = ty::Binder::bind(pred);
// `<Foo as Iterator>::Item = String`.
let trait_ref =
@ -651,7 +650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bound_span_label(trait_ref.self_ty(), &obligation, &quiet);
Some((obligation, trait_ref.self_ty()))
}
&ty::PredicateKind::Trait(poly_trait_ref, _) => {
ty::PredicateAtom::Trait(poly_trait_ref, _) => {
let poly_trait_ref = ty::Binder::bind(poly_trait_ref);
let p = poly_trait_ref.skip_binder().trait_ref;
let self_ty = p.self_ty();
@ -959,11 +958,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// implementing a trait would be legal but is rejected
// here).
unsatisfied_predicates.iter().all(|(p, _)| {
match p.ignore_quantifiers().skip_binder().kind() {
match p.skip_binders() {
// Hide traits if they are present in predicates as they can be fixed without
// having to implement them.
ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id,
ty::PredicateKind::Projection(p) => {
ty::PredicateAtom::Trait(t, _) => t.def_id() == info.def_id,
ty::PredicateAtom::Projection(p) => {
p.projection_ty.item_def_id == info.def_id
}
_ => false,

View file

@ -2400,8 +2400,8 @@ fn bounds_from_generic_predicates<'tcx>(
let mut projections = vec![];
for (predicate, _) in predicates.predicates {
debug!("predicate {:?}", predicate);
match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(trait_predicate, _) => {
match predicate.skip_binders() {
ty::PredicateAtom::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() {
@ -2410,7 +2410,7 @@ fn bounds_from_generic_predicates<'tcx>(
entry.push(trait_predicate.def_id());
}
}
ty::PredicateKind::Projection(projection_pred) => {
ty::PredicateAtom::Projection(projection_pred) => {
projections.push(ty::Binder::bind(projection_pred));
}
_ => {}
@ -2938,9 +2938,9 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
parent: None,
predicates: tcx.arena.alloc_from_iter(
self.param_env.caller_bounds().iter().filter_map(|predicate| {
match predicate.kind() {
ty::PredicateKind::Trait(ref data, _)
if data.skip_binder().self_ty().is_param(index) =>
match predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _)
if data.self_ty().is_param(index) =>
{
// HACK(eddyb) should get the original `Span`.
let span = tcx.def_span(def_id);
@ -3612,7 +3612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_predicate(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx),
ty::PredicateAtom::WellFormed(arg).to_predicate(self.tcx),
));
}
@ -3894,23 +3894,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.pending_obligations()
.into_iter()
.filter_map(move |obligation| {
match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::Projection(data) => {
match obligation.predicate.skip_binders() {
ty::PredicateAtom::Projection(data) => {
Some((ty::Binder::bind(data).to_poly_trait_ref(self.tcx), obligation))
}
&ty::PredicateKind::Trait(data, _) => {
ty::PredicateAtom::Trait(data, _) => {
Some((ty::Binder::bind(data).to_poly_trait_ref(), obligation))
}
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,
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,
// N.B., this predicate is created by breaking down a
// `ClosureType: FnFoo()` predicate, where
// `ClosureType` represents some `Closure`. It can't
@ -3919,7 +3916,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this closure yet; this is exactly why the other
// code is looking for a self type of a unresolved
// inference variable.
ty::PredicateKind::ClosureKind(..) => None,
ty::PredicateAtom::ClosureKind(..) => None,
}
})
.filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root))
@ -4249,8 +4246,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
continue;
}
if let ty::PredicateKind::Trait(predicate, _) =
error.obligation.predicate.ignore_quantifiers().skip_binder().kind()
if let ty::PredicateAtom::Trait(predicate, _) =
error.obligation.predicate.skip_binders()
{
// Collect the argument position for all arguments that could have caused this
// `FulfillmentError`.
@ -4298,8 +4295,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let hir::ExprKind::Path(qpath) = &path.kind {
if let hir::QPath::Resolved(_, path) = &qpath {
for error in errors {
if let ty::PredicateKind::Trait(predicate, _) =
error.obligation.predicate.ignore_quantifiers().skip_binder().kind()
if let ty::PredicateAtom::Trait(predicate, _) =
error.obligation.predicate.skip_binders()
{
// If any of the type arguments in this path segment caused the
// `FullfillmentError`, point at its span (#61860).
@ -5372,7 +5369,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_def_id,
};
let predicate = ty::PredicateKind::Projection(ty::ProjectionPredicate {
let predicate = ty::PredicateAtom::Projection(ty::ProjectionPredicate {
projection_ty,
ty: expected,
})

View file

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

View file

@ -552,8 +552,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.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index),
.filter(|(predicate, _)| match predicate.skip_binders() {
ty::PredicateAtom::Trait(data, _) => data.self_ty().is_param(index),
_ => false,
}),
);
@ -1004,7 +1004,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::PredicateKind::Trait(bound, _) = pred.ignore_quantifiers().skip_binder().kind() {
if let ty::PredicateAtom::Trait(bound, _) = pred.skip_binders() {
tcx.at(span).super_predicates_of(bound.def_id());
}
}
@ -1960,7 +1960,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
&hir::GenericBound::Outlives(ref lifetime) => {
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
predicates.push((
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region))
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
.to_predicate(tcx)
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
lifetime.span,
@ -1979,7 +1979,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
}
_ => bug!(),
};
let pred = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(icx.tcx);
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
@ -2110,7 +2110,7 @@ fn predicates_from_bound<'tcx>(
}
hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
let pred = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
.to_predicate(astconv.tcx())
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
vec![(pred, lifetime.span)]

View file

@ -182,9 +182,7 @@ 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::PredicateKind::Projection(projection) =
predicates[j].0.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Projection(projection) = predicates[j].0.skip_binders() {
// Special case: watch out for some kind of sneaky attempt
// to project out an associated type defined by this very
// trait.

View file

@ -198,9 +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::PredicateKind::Projection(proj) =
predicate.ignore_quantifiers().skip_binder().kind()
{
if let ty::PredicateAtom::Projection(proj) = predicate.skip_binders() {
let projection_ty = proj.projection_ty;
let projected_ty = proj.ty;
@ -361,13 +359,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.ignore_quantifiers().skip_binder().kind() {
match predicate.skip_binders() {
// 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::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
if !matches!(
trait_predicate_kind(tcx, predicate),
Some(TraitSpecializationKind::Marker)
@ -394,20 +392,19 @@ fn trait_predicate_kind<'tcx>(
tcx: TyCtxt<'tcx>,
predicate: ty::Predicate<'tcx>,
) -> Option<TraitSpecializationKind> {
match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
match predicate.skip_binders() {
ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
Some(tcx.trait_def(pred.def_id()).specialization_kind)
}
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(..) => None,
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(..) => None,
}
}

View file

@ -29,10 +29,8 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
// process predicates and convert to `RequiredPredicates` entry, see below
for &(predicate, span) in predicates.predicates {
match predicate.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unepected predicate: {:?}", predicate),
ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
match predicate.skip_binders() {
ty::PredicateAtom::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
insert_outlives_predicate(
tcx,
(*ty).into(),
@ -42,7 +40,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
)
}
ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
insert_outlives_predicate(
tcx,
(*reg1).into(),
@ -52,14 +50,14 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
)
}
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::PredicateAtom::Trait(..)
| ty::PredicateAtom::Projection(..)
| ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => (),
}
}

View file

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

View file

@ -315,11 +315,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> FxHashSet<GenericParamDef> {
let regions = match pred.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(poly_trait_pred, _) => {
let regions = match pred.skip_binders() {
ty::PredicateAtom::Trait(poly_trait_pred, _) => {
tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(poly_trait_pred))
}
&ty::PredicateKind::Projection(poly_proj_pred) => {
ty::PredicateAtom::Projection(poly_proj_pred) => {
tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(poly_proj_pred))
}
_ => return FxHashSet::default(),
@ -465,8 +465,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.iter()
.filter(|p| {
!orig_bounds.contains(p)
|| match p.ignore_quantifiers().skip_binder().kind() {
ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
|| match p.skip_binders() {
ty::PredicateAtom::Trait(pred, _) => pred.def_id() == sized_trait,
_ => false,
}
})

View file

@ -480,19 +480,18 @@ impl Clean<WherePredicate> for hir::WherePredicate<'_> {
impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
match self.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(pred, _) => Some(ty::Binder::bind(pred).clean(cx)),
&ty::PredicateKind::Subtype(pred) => Some(ty::Binder::bind(pred).clean(cx)),
&ty::PredicateKind::RegionOutlives(pred) => ty::Binder::bind(pred).clean(cx),
&ty::PredicateKind::TypeOutlives(pred) => ty::Binder::bind(pred).clean(cx),
&ty::PredicateKind::Projection(pred) => Some(ty::Binder::bind(pred).clean(cx)),
match self.skip_binders() {
ty::PredicateAtom::Trait(pred, _) => Some(ty::Binder::bind(pred).clean(cx)),
ty::PredicateAtom::Subtype(pred) => Some(ty::Binder::bind(pred).clean(cx)),
ty::PredicateAtom::RegionOutlives(pred) => ty::Binder::bind(pred).clean(cx),
ty::PredicateAtom::TypeOutlives(pred) => ty::Binder::bind(pred).clean(cx),
ty::PredicateAtom::Projection(pred) => Some(ty::Binder::bind(pred).clean(cx)),
ty::PredicateKind::ForAll(_) => panic!("unexpected predicate: {:?}", self),
ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => panic!("not user writable"),
ty::PredicateAtom::WellFormed(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => panic!("not user writable"),
}
}
}
@ -755,18 +754,18 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
.flat_map(|(p, _)| {
let mut projection = None;
let param_idx = (|| {
match p.ignore_quantifiers().skip_binder().kind() {
&ty::PredicateKind::Trait(pred, _constness) => {
match p.skip_binders() {
ty::PredicateAtom::Trait(pred, _constness) => {
if let ty::Param(param) = pred.self_ty().kind {
return Some(param.index);
}
}
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
if let ty::Param(param) = ty.kind {
return Some(param.index);
}
}
&ty::PredicateKind::Projection(p) => {
ty::PredicateAtom::Projection(p) => {
if let ty::Param(param) = p.projection_ty.self_ty().kind {
projection = Some(ty::Binder::bind(p));
return Some(param.index);
@ -1663,15 +1662,11 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
.filter_map(|predicate| {
// Note: The substs of opaque types can contain unbound variables,
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
let trait_ref = match predicate
.ignore_quantifiers_with_unbound_vars(cx.tcx)
.skip_binder()
.kind()
{
ty::PredicateKind::Trait(tr, _constness) => {
let trait_ref = match predicate.bound_atom(cx.tcx).skip_binder() {
ty::PredicateAtom::Trait(tr, _constness) => {
ty::Binder::bind(tr.trait_ref)
}
ty::PredicateKind::TypeOutlives(pred) => {
ty::PredicateAtom::TypeOutlives(pred) => {
if let Some(r) = pred.1.clean(cx) {
regions.push(GenericBound::Outlives(r));
}
@ -1691,10 +1686,9 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
.predicates
.iter()
.filter_map(|pred| {
if let ty::PredicateKind::Projection(proj) = pred
.ignore_quantifiers_with_unbound_vars(cx.tcx)
.skip_binder()
.kind()
// We never rebind `proj`, so `skip_binders_unchecked` is safe here.
if let ty::PredicateAtom::Projection(proj) =
pred.skip_binders_unchecked()
{
if proj.projection_ty.trait_ref(cx.tcx)
== trait_ref.skip_binder()

View file

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

View file

@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, HirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
cx.tcx.infer_ctxt().enter(|infcx| {
for FulfillmentError { obligation, .. } in send_errors {
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
if let Trait(trait_pred, _) = obligation.predicate.ignore_quantifiers().skip_binder().kind() {
if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
db.note(&format!(
"`{}` doesn't implement `{}`",
trait_pred.self_ty(),

View file

@ -1559,7 +1559,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let ty::Opaque(def_id, _) = ret_ty.kind {
// one of the associated types must be Self
for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_quantifiers().skip_binder().kind() {
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
// walk the associated type and check for Self
if contains_self_ty(projection_predicate.ty) {
return;

View file

@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
.filter(|p| !p.is_global())
.filter_map(|obligation| {
// Note that we do not want to deal with qualified predicates here.
if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() {
if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
if pred.def_id() == sized_trait {
return None;
}

View file

@ -1263,7 +1263,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.predicates_of(*def_id).predicates {
if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_quantifiers().skip_binder().kind() {
if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() {
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
return true;
}