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(..) => {
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,
});
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),
));
}
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(),
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))
+ }
+ })
}
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,
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,
}
}
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());
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
if r.is_late_bound() {
None
} else {
- Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
+ Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
r, r_min,
)))
}
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,
)))
}
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);
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",
Subtype(..) |
ConstEvaluatable(..) |
ConstEquate(..) => continue,
- ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
};
if predicate.is_global() {
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {
) -> 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,
},
) -> 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,
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 =
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();
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);
+ }
+ },
}
}
}
#[cfg(target_arch = "x86_64")]
-static_assert_size!(PredicateInner<'_>, 40);
+static_assert_size!(PredicateInner<'_>, 48);
#[derive(Clone, Copy, Lift)]
pub struct 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.
- ///
- /// This method requires the `TyCtxt` as it has to shift the unbound variables
- /// outwards.
+ /// Returns the inner `PredicateAtom`.
///
- /// 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.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,
- 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.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),
}
}
#[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.
/// 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
// 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
+ }
}
}
}
}
+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)
}
}
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)
}
- .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)
}
- .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)
}
- .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)
}
- .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,
+ }
}
}
// 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.
ty::Predicate<'tcx> {
match self.kind() {
- &ty::PredicateKind::Trait(ref data, constness) => {
- if let hir::Constness::Const = constness {
- p!(write("const "));
+ &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::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::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
+ p!(write("the closure `"),
+ print_value_path(closure_def_id, &[]),
+ write("` implements the trait `{}`", kind))
+ }
+ ty::PredicateAtom::ConstEvaluatable(def, substs) => {
+ p!(write("the constant `"),
+ print_value_path(def.did, substs),
+ write("` can be evaluated"))
+ }
+ ty::PredicateAtom::ConstEquate(c1, c2) => {
+ p!(write("the constant `"),
+ print(c1),
+ write("` equals `"),
+ print(c2),
+ write("`"))
}
- 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) => {
- p!(write("the trait `"),
- print_def_path(trait_def_id, &[]),
- write("` is object-safe"))
- }
- &ty::PredicateKind::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) => {
- p!(write("the constant `"),
- print_value_path(def.did, substs),
- write("` can be evaluated"))
- }
- ty::PredicateKind::ConstEquate(c1, c2) => {
- p!(write("the constant `"),
- print(c1),
- write("` equals `"),
- print(c2),
- write("`"))
}
ty::PredicateKind::ForAll(binder) => {
p!(print(binder))
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),
}
}
}
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::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::PredicateKind::Subtype(ref data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
- ty::PredicateKind::RegionOutlives(ref data) => {
- tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
+ 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::PredicateKind::TypeOutlives(ref data) => {
- tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
+ ty::PredicateAtom::TypeOutlives(ref data) => {
+ tcx.lift(data).map(ty::PredicateAtom::TypeOutlives)
}
- ty::PredicateKind::Projection(ref data) => {
- tcx.lift(data).map(ty::PredicateKind::Projection)
+ ty::PredicateAtom::Projection(ref data) => {
+ tcx.lift(data).map(ty::PredicateAtom::Projection)
}
- ty::PredicateKind::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateKind::WellFormed),
- ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
+ 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::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
+ ty::PredicateAtom::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::PredicateAtom::ObjectSafe(trait_def_id) => {
+ Some(ty::PredicateAtom::ObjectSafe(trait_def_id))
}
- ty::PredicateKind::ConstEquate(c1, c2) => {
- tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
+ ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
+ tcx.lift(&substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs))
}
- ty::PredicateKind::ForAll(ref binder) => {
- tcx.lift(binder).map(ty::PredicateKind::ForAll)
+ ty::PredicateAtom::ConstEquate(c1, c2) => {
+ tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
}
}
}
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;
}
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,
);
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
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,
);
category: ConstraintCategory,
) {
self.prove_predicates(
- Some(ty::PredicateKind::Trait(
+ Some(ty::PredicateAtom::Trait(
ty::TraitPredicate { trait_ref },
hir::Constness::NotConst,
)),
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;
}
}
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),
}
}
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;
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
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;
// 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
}
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 {:?}",
}
}
}
- &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(),
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);
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
)
}
- 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,
)
}
- &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(
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
}
}
- ty::PredicateKind::ConstEvaluatable(..) => {
+ ty::PredicateAtom::ConstEvaluatable(..) => {
// Errors for `ConstEvaluatable` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
)
}
- ty::PredicateKind::ConstEquate(..) => {
+ ty::PredicateAtom::ConstEquate(..) => {
// Errors for `ConstEquate` predicates show up as
// `SelectionError::ConstEvalFailure`,
// not `Unimplemented`.
}
// 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))
}
_ => {
};
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.
//
// 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,
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);
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() {
}
}
- 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;
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(),
- ) {
- (
- ty::PredicateKind::Trait(pred, _),
- &ObligationCauseCode::BindingObligation(item_def_id, span),
- ) => (pred, item_def_id, span),
- _ => return,
- };
+ let (pred, item_def_id, span) =
+ match (obligation.predicate.skip_binders(), obligation.cause.code.peel_derives()) {
+ (
+ ty::PredicateAtom::Trait(pred, _),
+ &ObligationCauseCode::BindingObligation(item_def_id, span),
+ ) => (pred, item_def_id, span),
+ _ => return,
+ };
let node = match (
self.tcx.hir().get_if_local(item_def_id),
// 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())),
- _ => (None, None),
- };
+ 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;
let mut outer_generator = None;
let mut next_code = Some(&obligation.cause.code);
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,
+ trait_obligation,
+ &mut pending_obligation.stalled_on,
+ )
+ }
+ ty::PredicateAtom::Projection(projection) => {
+ let project_obligation = obligation.with(Binder::bind(projection));
+
+ self.process_projection_obligation(
+ project_obligation,
+ &mut pending_obligation.stalled_on,
+ )
+ }
+ ty::PredicateAtom::RegionOutlives(_)
+ | ty::PredicateAtom::TypeOutlives(_)
+ | ty::PredicateAtom::WellFormed(_)
+ | ty::PredicateAtom::ObjectSafe(_)
+ | ty::PredicateAtom::ClosureKind(..)
+ | ty::PredicateAtom::Subtype(_)
+ | ty::PredicateAtom::ConstEvaluatable(..)
+ | ty::PredicateAtom::ConstEquate(..) => {
+ let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
+ ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
+ }
+ },
+ },
+ &ty::PredicateKind::Atom(atom) => match atom {
+ ty::PredicateAtom::Trait(ref data, _) => {
+ let trait_obligation = obligation.with(Binder::dummy(*data));
self.process_trait_obligation(
obligation,
&mut pending_obligation.stalled_on,
)
}
- ty::PredicateKind::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(_) => {
- let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
- ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
- }
- },
- ty::PredicateKind::Trait(ref data, _) => {
- let trait_obligation = obligation.with(Binder::dummy(*data));
-
- self.process_trait_obligation(
- obligation,
- trait_obligation,
- &mut pending_obligation.stalled_on,
- )
- }
- &ty::PredicateKind::RegionOutlives(data) => {
- match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
- Ok(()) => ProcessResult::Changed(vec![]),
- Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
+ ty::PredicateAtom::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)) => {
- if self.register_region_obligations {
- self.selcx.infcx().register_region_obligation_with_cause(
- t_a,
- r_b,
- &obligation.cause,
- );
+ ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
+ if self.register_region_obligations {
+ self.selcx.infcx().register_region_obligation_with_cause(
+ t_a,
+ r_b,
+ &obligation.cause,
+ );
+ }
+ ProcessResult::Changed(vec![])
}
- ProcessResult::Changed(vec![])
- }
- ty::PredicateKind::Projection(ref data) => {
- let project_obligation = obligation.with(Binder::dummy(*data));
+ ty::PredicateAtom::Projection(ref data) => {
+ let project_obligation = obligation.with(Binder::dummy(*data));
- self.process_projection_obligation(
- project_obligation,
- &mut pending_obligation.stalled_on,
- )
- }
+ self.process_projection_obligation(
+ project_obligation,
+ &mut pending_obligation.stalled_on,
+ )
+ }
- &ty::PredicateKind::ObjectSafe(trait_def_id) => {
- if !self.selcx.tcx().is_object_safe(trait_def_id) {
- ProcessResult::Error(CodeSelectionError(Unimplemented))
- } else {
- ProcessResult::Changed(vec![])
+ ty::PredicateAtom::ObjectSafe(trait_def_id) => {
+ if !self.selcx.tcx().is_object_safe(trait_def_id) {
+ ProcessResult::Error(CodeSelectionError(Unimplemented))
+ } else {
+ ProcessResult::Changed(vec![])
+ }
}
- }
- &ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
- match self.selcx.infcx().closure_kind(closure_substs) {
- Some(closure_kind) => {
- if closure_kind.extends(kind) {
- ProcessResult::Changed(vec![])
- } else {
- ProcessResult::Error(CodeSelectionError(Unimplemented))
+ ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
+ match self.selcx.infcx().closure_kind(closure_substs) {
+ Some(closure_kind) => {
+ if closure_kind.extends(kind) {
+ ProcessResult::Changed(vec![])
+ } else {
+ ProcessResult::Error(CodeSelectionError(Unimplemented))
+ }
}
+ None => ProcessResult::Unchanged,
}
- None => ProcessResult::Unchanged,
}
- }
- &ty::PredicateKind::WellFormed(arg) => {
- match wf::obligations(
- self.selcx.infcx(),
- obligation.param_env,
- obligation.cause.body_id,
- arg,
- obligation.cause.span,
- ) {
- None => {
- pending_obligation.stalled_on =
- vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
- ProcessResult::Unchanged
+ ty::PredicateAtom::WellFormed(arg) => {
+ match wf::obligations(
+ self.selcx.infcx(),
+ obligation.param_env,
+ obligation.cause.body_id,
+ arg,
+ obligation.cause.span,
+ ) {
+ None => {
+ pending_obligation.stalled_on =
+ vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
+ ProcessResult::Unchanged
+ }
+ Some(os) => ProcessResult::Changed(mk_pending(os)),
}
- Some(os) => ProcessResult::Changed(mk_pending(os)),
}
- }
- &ty::PredicateKind::Subtype(subtype) => {
- match self.selcx.infcx().subtype_predicate(
- &obligation.cause,
- obligation.param_env,
- Binder::dummy(subtype),
- ) {
- None => {
- // None means that both are unresolved.
- pending_obligation.stalled_on = vec![
- TyOrConstInferVar::maybe_from_ty(subtype.a).unwrap(),
- TyOrConstInferVar::maybe_from_ty(subtype.b).unwrap(),
- ];
- ProcessResult::Unchanged
- }
- Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
- Some(Err(err)) => {
- let expected_found =
- ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
- ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
- expected_found,
- err,
- ))
+ ty::PredicateAtom::Subtype(subtype) => {
+ match self.selcx.infcx().subtype_predicate(
+ &obligation.cause,
+ obligation.param_env,
+ Binder::dummy(subtype),
+ ) {
+ None => {
+ // None means that both are unresolved.
+ pending_obligation.stalled_on = vec![
+ TyOrConstInferVar::maybe_from_ty(subtype.a).unwrap(),
+ TyOrConstInferVar::maybe_from_ty(subtype.b).unwrap(),
+ ];
+ ProcessResult::Unchanged
+ }
+ Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
+ Some(Err(err)) => {
+ let expected_found =
+ ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
+ ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
+ expected_found,
+ err,
+ ))
+ }
}
}
- }
- &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
- match self.selcx.infcx().const_eval_resolve(
- obligation.param_env,
- def_id,
- substs,
- None,
- Some(obligation.cause.span),
- ) {
- Ok(_) => ProcessResult::Changed(vec![]),
- Err(err) => ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))),
+ ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
+ match self.selcx.infcx().const_eval_resolve(
+ obligation.param_env,
+ def_id,
+ substs,
+ None,
+ Some(obligation.cause.span),
+ ) {
+ Ok(_) => ProcessResult::Changed(vec![]),
+ Err(err) => ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))),
+ }
}
- }
- 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;
);
Err(ErrorHandled::TooGeneric)
}
- Err(err) => Err(err),
+ } else {
+ Ok(c)
}
- } else {
- Ok(c)
- }
- };
-
- match (evaluate(c1), evaluate(c2)) {
- (Ok(c1), Ok(c2)) => {
- match self
- .selcx
- .infcx()
- .at(&obligation.cause, obligation.param_env)
- .eq(c1, c2)
- {
- Ok(_) => ProcessResult::Changed(vec![]),
- Err(err) => {
- ProcessResult::Error(FulfillmentErrorCode::CodeConstEquateError(
- ExpectedFound::new(true, c1, c2),
- err,
- ))
+ };
+
+ match (evaluate(c1), evaluate(c2)) {
+ (Ok(c1), Ok(c2)) => {
+ match self
+ .selcx
+ .infcx()
+ .at(&obligation.cause, obligation.param_env)
+ .eq(c1, c2)
+ {
+ Ok(_) => ProcessResult::Changed(vec![]),
+ 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!(
- obligation.cause.span(self.selcx.tcx()),
- "ConstEquate: const_eval_resolve returned an unexpected error"
- ),
- (Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
- ProcessResult::Unchanged
+ (Err(ErrorHandled::Reported(ErrorReported)), _)
+ | (_, 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
+ }
}
}
- }
+ },
}
}
// 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();
.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
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()
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,
}
})
}
.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
// 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()
}
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;
// 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)
- if data.projection_ty.item_def_id == obligation.predicate.item_def_id =>
- {
- Some(ty::Binder::bind(data))
- }
- _ => None,
+ 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
// `&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) {
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()),
));
}
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) {
}
}
- &ty::PredicateKind::WellFormed(arg) => match wf::obligations(
+ ty::PredicateAtom::WellFormed(arg) => match wf::obligations(
self.infcx,
obligation.param_env,
obligation.cause.body_id,
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 {
}
}
- &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) {
}
}
- &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) {
}
}
- &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
+ ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
match self.tcx().const_eval_resolve(
obligation.param_env,
def_id,
}
}
- 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>| {
}
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);
};
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)
// 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, _) => {
- wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
- }
- ty::PredicateKind::RegionOutlives(..) => {}
- &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
- wf.compute(ty.into());
- }
- ty::PredicateKind::Projection(t) => {
- wf.compute_projection(t.projection_ty);
- wf.compute(t.ty.into());
- }
- &ty::PredicateKind::WellFormed(arg) => {
- wf.compute(arg);
- }
- ty::PredicateKind::ObjectSafe(_) => {}
- ty::PredicateKind::ClosureKind(..) => {}
- &ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
- wf.compute(a.into());
- wf.compute(b.into());
- }
- &ty::PredicateKind::ConstEvaluatable(def, substs) => {
- let obligations = wf.nominal_obligations(def.did, substs);
- wf.out.extend(obligations);
-
- for arg in substs.iter() {
+ &ty::PredicateKind::Atom(atom) => match atom {
+ ty::PredicateAtom::Trait(t, _) => {
+ wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
+ }
+ ty::PredicateAtom::RegionOutlives(..) => {}
+ ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
+ wf.compute(ty.into());
+ }
+ ty::PredicateAtom::Projection(t) => {
+ wf.compute_projection(t.projection_ty);
+ wf.compute(t.ty.into());
+ }
+ ty::PredicateAtom::WellFormed(arg) => {
wf.compute(arg);
}
- }
- &ty::PredicateKind::ConstEquate(c1, c2) => {
- wf.compute(c1.into());
- wf.compute(c2.into());
- }
+ 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::PredicateAtom::ConstEvaluatable(def, substs) => {
+ let obligations = wf.nominal_obligations(def.did, substs);
+ wf.out.extend(obligations);
+
+ for arg in substs.iter() {
+ wf.compute(arg);
+ }
+ }
+ ty::PredicateAtom::ConstEquate(c1, c2) => {
+ wf.compute(c1.into());
+ wf.compute(c2.into());
+ }
+ },
}
wf.normalize()
};
// 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
}
}
}
- 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);
traits::Obligation::new(
new_cause,
param_env,
- ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
+ ty::PredicateAtom::WellFormed(arg).to_predicate(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(
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()),
));
}
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()),
));
}
traits::Obligation::new(
cause.clone(),
param_env,
- ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
+ ty::PredicateAtom::ObjectSafe(did).to_predicate(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.
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);
.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);
)
}
// 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);
.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)
}
}
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);
)
}
// 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
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))
}
}
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);
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);
}),
))
}
- ty::PredicateKind::TypeOutlives(_predicate) => None,
- ty::PredicateKind::Projection(_predicate) => None,
- ty::PredicateKind::WellFormed(_ty) => None,
-
- ty::PredicateKind::ObjectSafe(..)
- | ty::PredicateKind::ClosureKind(..)
- | ty::PredicateKind::Subtype(..)
- | ty::PredicateKind::ConstEvaluatable(..)
- | ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
+ ty::PredicateAtom::TypeOutlives(_predicate) => None,
+ ty::PredicateAtom::Projection(_predicate) => None,
+ ty::PredicateAtom::WellFormed(_ty) => None,
+
+ ty::PredicateAtom::ObjectSafe(..)
+ | ty::PredicateAtom::ClosureKind(..)
+ | ty::PredicateAtom::Subtype(..)
+ | ty::PredicateAtom::ConstEvaluatable(..)
+ | ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
}
}
}
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) => {
- wf_args.push(arg);
- vec![]
- }
+ &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)) => {
- vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
- }
+ 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)) => {
- 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)
- }
+ 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)
+ }
+ },
}
}));
}
}
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,
}
}
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()),
);
}
// 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(())
}
}
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);
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 {
}
}
}
- 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);
}
}
// These can come from elaborating other predicates
- ty::PredicateKind::RegionOutlives(_) => return None,
+ ty::PredicateAtom::RegionOutlives(_) => return None,
_ => {}
}
tcx.sess.delay_span_bug(
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())
.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.
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.
// 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,
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() {
// 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,
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
- .predicates
- .iter()
- .zip(predicates.spans.iter())
- .find_map(|(p, span)| {
- if *p == obligation.predicate { Some(*span) } else { None }
- })
- .unwrap_or(rustc_span::DUMMY_SP);
- Some((trait_pred, span))
- }
- _ => None,
+ .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)| {
+ 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),
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 };
// 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| {
// 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))
}
};
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 =
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();
// 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,
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() {
entry.push(trait_predicate.def_id());
}
}
- ty::PredicateKind::Projection(projection_pred) => {
+ ty::PredicateAtom::Projection(projection_pred) => {
projections.push(ty::Binder::bind(projection_pred));
}
_ => {}
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);
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),
));
}
.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
// 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))
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`.
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).
item_def_id,
};
- let predicate = ty::PredicateKind::Projection(ty::ProjectionPredicate {
+ let predicate = ty::PredicateAtom::Projection(ty::ProjectionPredicate {
projection_ty,
ty: expected,
})
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,
)
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,
}),
);
// 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());
}
}
&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,
}
_ => 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)
}
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)]
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.
// 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;
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)
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,
}
}
// 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(),
)
}
- ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
+ ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
insert_outlives_predicate(
tcx,
(*reg1).into(),
)
}
- 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(..) => (),
}
}
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();
|(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)
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(),
.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,
}
})
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"),
}
}
}
.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);
.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));
}
.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()
.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
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;
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(),
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;
.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;
}
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;
}