PredicateKint -> PredicateKind, the beginning of the end

This commit is contained in:
Bastian Kauschke 2020-06-18 20:41:43 +02:00
parent 506f4308b7
commit 9852b42b58
59 changed files with 744 additions and 742 deletions

View file

@ -531,12 +531,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
GenericArg<'tcx>,
ty::Region<'tcx>,
>| match k1.unpack() {
GenericArgKind::Lifetime(r1) => self.tcx.intern_predicate_kint(
ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
),
GenericArgKind::Type(t1) => self.tcx.intern_predicate_kint(
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(t1, r2)),
),
GenericArgKind::Lifetime(r1) => {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Type(t1) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Const(..) => {
// Consts cannot outlive one another, so we don't expect to
// ecounter this branch.
@ -545,9 +547,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
};
let predicate = if let Some(constraint) = constraint.no_bound_vars() {
to_predicate(constraint).to_predicate(self.tcx)
to_predicate(constraint)
} else {
ty::PredicateKint::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
ty::PredicateKind::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
};
Obligation::new(cause.clone(), param_env, predicate)
@ -670,7 +672,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
self.obligations.push(Obligation {
cause: self.cause.clone(),
param_env: self.param_env,
predicate: ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(sup, sub))
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
.to_predicate(self.infcx.tcx),
recursion_depth: 0,
});

View file

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

View file

@ -3,7 +3,7 @@ use crate::infer::{GenericKind, InferCtxt};
use crate::traits::query::OutlivesBound;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_middle::ty::{self, TyCtxt};
use super::explicit_outlives_bounds;
@ -69,7 +69,7 @@ pub struct OutlivesEnvironment<'tcx> {
pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;
impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
let mut env = OutlivesEnvironment {
param_env,
free_region_map: Default::default(),
@ -77,7 +77,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
region_bound_pairs_accum: vec![],
};
env.add_outlives_bounds(None, explicit_outlives_bounds(param_env));
env.add_outlives_bounds(None, explicit_outlives_bounds(tcx, param_env));
env
}

View file

@ -5,9 +5,10 @@ pub mod obligations;
pub mod verify;
use rustc_middle::traits::query::OutlivesBound;
use rustc_middle::ty;
use rustc_middle::ty::{self, TyCtxt};
pub fn explicit_outlives_bounds<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
debug!("explicit_outlives_bounds()");

View file

@ -331,8 +331,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
compare_ty: impl Fn(Ty<'tcx>) -> bool,
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
) -> impl Iterator<Item = ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
let tcx = self.tcx;
predicates
.filter_map(|p| p.to_opt_type_outlives())
.filter_map(move |p| p.to_opt_type_outlives(tcx))
.filter_map(|p| p.no_bound_vars())
.filter(move |p| compare_ty(p.0))
}

View file

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

View file

@ -10,34 +10,34 @@ pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> ty::Predicate<'tcx> {
let kind = pred.kint(tcx);
let kind = pred.kind();
let new = match kind {
ty::PredicateKint::ForAll(binder) => {
ty::PredicateKint::ForAll(tcx.anonymize_late_bound_regions(binder))
ty::PredicateKind::ForAll(binder) => {
ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder))
}
&ty::PredicateKint::Trait(data, constness) => ty::PredicateKint::Trait(data, constness),
&ty::PredicateKind::Trait(data, constness) => ty::PredicateKind::Trait(data, constness),
&ty::PredicateKint::RegionOutlives(data) => ty::PredicateKint::RegionOutlives(data),
&ty::PredicateKind::RegionOutlives(data) => ty::PredicateKind::RegionOutlives(data),
&ty::PredicateKint::TypeOutlives(data) => ty::PredicateKint::TypeOutlives(data),
&ty::PredicateKind::TypeOutlives(data) => ty::PredicateKind::TypeOutlives(data),
&ty::PredicateKint::Projection(data) => ty::PredicateKint::Projection(data),
&ty::PredicateKind::Projection(data) => ty::PredicateKind::Projection(data),
&ty::PredicateKint::WellFormed(data) => ty::PredicateKint::WellFormed(data),
&ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
&ty::PredicateKint::ObjectSafe(data) => ty::PredicateKint::ObjectSafe(data),
&ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
&ty::PredicateKint::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKint::ClosureKind(closure_def_id, closure_substs, kind)
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
}
&ty::PredicateKint::Subtype(data) => ty::PredicateKint::Subtype(data),
&ty::PredicateKind::Subtype(data) => ty::PredicateKind::Subtype(data),
&ty::PredicateKint::ConstEvaluatable(def_id, substs) => {
ty::PredicateKint::ConstEvaluatable(def_id, substs)
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs)
}
&ty::PredicateKint::ConstEquate(c1, c2) => ty::PredicateKint::ConstEquate(c1, c2),
&ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
};
if new != *kind { new.to_predicate(tcx) } else { pred }
@ -145,22 +145,22 @@ fn predicate_obligation<'tcx>(
}
impl Elaborator<'tcx> {
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
FilterToTraits::new(self)
pub fn filter_to_traits(self) -> FilterToTraits<'tcx, Self> {
FilterToTraits::new(self.visited.tcx, self)
}
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
let pred = match obligation.predicate.kint(tcx) {
// We have to be careful and rebind this whenever
let pred = match obligation.predicate.kind() {
// We have to be careful and rebind this when
// dealing with a predicate further down.
ty::PredicateKint::ForAll(binder) => binder.skip_binder(),
ty::PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
pred => pred,
};
match pred {
ty::PredicateKint::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
ty::PredicateKint::Trait(ref data, _) => {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
ty::PredicateKind::Trait(data, _) => {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());
@ -181,36 +181,36 @@ impl Elaborator<'tcx> {
self.stack.extend(obligations);
}
ty::PredicateKint::WellFormed(..) => {
ty::PredicateKind::WellFormed(..) => {
// Currently, we do not elaborate WF predicates,
// although we easily could.
}
ty::PredicateKint::ObjectSafe(..) => {
ty::PredicateKind::ObjectSafe(..) => {
// Currently, we do not elaborate object-safe
// predicates.
}
ty::PredicateKint::Subtype(..) => {
ty::PredicateKind::Subtype(..) => {
// Currently, we do not "elaborate" predicates like `X <: Y`,
// though conceivably we might.
}
ty::PredicateKint::Projection(..) => {
ty::PredicateKind::Projection(..) => {
// Nothing to elaborate in a projection predicate.
}
ty::PredicateKint::ClosureKind(..) => {
ty::PredicateKind::ClosureKind(..) => {
// Nothing to elaborate when waiting for a closure's kind to be inferred.
}
ty::PredicateKint::ConstEvaluatable(..) => {
ty::PredicateKind::ConstEvaluatable(..) => {
// Currently, we do not elaborate const-evaluatable
// predicates.
}
ty::PredicateKint::ConstEquate(..) => {
ty::PredicateKind::ConstEquate(..) => {
// Currently, we do not elaborate const-equate
// predicates.
}
ty::PredicateKint::RegionOutlives(..) => {
ty::PredicateKind::RegionOutlives(..) => {
// Nothing to elaborate from `'a: 'b`.
}
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
// We know that `T: 'a` for some type `T`. We can
// often elaborate this. For example, if we know that
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@ -240,7 +240,7 @@ impl Elaborator<'tcx> {
if r.is_late_bound() {
None
} else {
Some(ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
r, r_min,
)))
}
@ -248,7 +248,7 @@ impl Elaborator<'tcx> {
Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name);
Some(ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty, r_min,
)))
}
@ -293,7 +293,7 @@ impl Iterator for Elaborator<'tcx> {
// Supertrait iterator
///////////////////////////////////////////////////////////////////////////
pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
pub type Supertraits<'tcx> = FilterToTraits<'tcx, Elaborator<'tcx>>;
pub fn supertraits<'tcx>(
tcx: TyCtxt<'tcx>,
@ -315,22 +315,23 @@ pub fn transitive_bounds<'tcx>(
/// A filter around an iterator of predicates that makes it yield up
/// just trait references.
pub struct FilterToTraits<I> {
pub struct FilterToTraits<'tcx, I> {
tcx: TyCtxt<'tcx>,
base_iterator: I,
}
impl<I> FilterToTraits<I> {
fn new(base: I) -> FilterToTraits<I> {
FilterToTraits { base_iterator: base }
impl<'tcx, I> FilterToTraits<'tcx, I> {
fn new(tcx: TyCtxt<'tcx>, base: I) -> FilterToTraits<'tcx, I> {
FilterToTraits { tcx, base_iterator: base }
}
}
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<'tcx, I> {
type Item = ty::PolyTraitRef<'tcx>;
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
while let Some(obligation) = self.base_iterator.next() {
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref(self.tcx) {
return Some(data);
}
}

View file

@ -1202,7 +1202,7 @@ declare_lint_pass!(
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PredicateKint::*;
use rustc_middle::ty::PredicateKind::*;
if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
@ -1210,7 +1210,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
for &(predicate, span) in predicates.predicates {
// We don't actually look inside of the predicate,
// so it is safe to skip this binder here.
let predicate_kind_name = match predicate.kint(cx.tcx).ignore_qualifiers().skip_binder() {
let predicate_kind_name = match predicate.ignore_qualifiers(cx.tcx).skip_binder().kind() {
Trait(..) => "Trait",
TypeOutlives(..) |
RegionOutlives(..) => "Lifetime",
@ -1495,34 +1495,32 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
impl ExplicitOutlivesRequirements {
fn lifetimes_outliving_lifetime<'tcx>(
tcx: TyCtxt<'tcx>,
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
index: u32,
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.kind() {
ty::PredicateKind::RegionOutlives(outlives) => {
let outlives = outlives.skip_binder();
match outlives.0 {
ty::ReEarlyBound(ebr) if ebr.index == index => Some(outlives.1),
_ => None,
}
}
.filter_map(|(pred, _)| match pred.ignore_qualifiers(tcx).skip_binder().kind() {
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
_ => None,
},
_ => None,
})
.collect()
}
fn lifetimes_outliving_type<'tcx>(
tcx: TyCtxt<'tcx>,
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
index: u32,
) -> Vec<ty::Region<'tcx>> {
inferred_outlives
.iter()
.filter_map(|(pred, _)| match pred.kind() {
ty::PredicateKind::TypeOutlives(outlives) => {
let outlives = outlives.skip_binder();
outlives.0.is_param(index).then_some(outlives.1)
.filter_map(|(pred, _)| match pred.ignore_qualifiers(tcx).skip_binder().kind() {
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
a.is_param(index).then_some(b)
}
_ => None,
})
@ -1541,10 +1539,10 @@ impl ExplicitOutlivesRequirements {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {
Self::lifetimes_outliving_lifetime(inferred_outlives, index)
Self::lifetimes_outliving_lifetime(tcx, inferred_outlives, index)
}
hir::GenericParamKind::Type { .. } => {
Self::lifetimes_outliving_type(inferred_outlives, index)
Self::lifetimes_outliving_type(tcx, inferred_outlives, index)
}
hir::GenericParamKind::Const { .. } => Vec::new(),
}
@ -1696,7 +1694,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
cx.tcx.named_region(predicate.lifetime.hir_id)
{
(
Self::lifetimes_outliving_lifetime(inferred_outlives, index),
Self::lifetimes_outliving_lifetime(
cx.tcx,
inferred_outlives,
index,
),
&predicate.bounds,
predicate.span,
)
@ -1712,7 +1714,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
if let Res::Def(DefKind::TyParam, def_id) = path.res {
let index = ty_generics.param_def_id_to_index[&def_id];
(
Self::lifetimes_outliving_type(inferred_outlives, index),
Self::lifetimes_outliving_type(
cx.tcx,
inferred_outlives,
index,
),
&predicate.bounds,
predicate.span,
)

View file

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

View file

@ -39,7 +39,7 @@ impl<'tcx> EncodableWithShorthand for Ty<'tcx> {
}
impl<'tcx> EncodableWithShorthand for ty::Predicate<'tcx> {
type Variant = ty::PredicateKynd<'tcx>;
type Variant = ty::PredicateKind<'tcx>;
fn variant(&self) -> &Self::Variant {
self.kind()
}
@ -195,7 +195,7 @@ where
})
} else {
let tcx = decoder.tcx();
Ok(tcx.mk_predicate(ty::PredicateKynd::decode(decoder)?))
Ok(tcx.mk_predicate(ty::PredicateKind::decode(decoder)?))
}
}

View file

@ -20,8 +20,8 @@ use crate::ty::{
self, query, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
PredicateKint, ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind,
TyS, TyVar, TyVid, TypeAndMut,
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
TyVid, TypeAndMut,
};
use rustc_ast::ast;
use rustc_ast::expand::allocator::AllocatorKind;
@ -79,7 +79,6 @@ pub struct CtxtInterners<'tcx> {
region: InternedSet<'tcx, RegionKind>,
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
predicate: InternedSet<'tcx, PredicateInner<'tcx>>,
predicate_kint: InternedSet<'tcx, PredicateKint<'tcx>>,
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
projs: InternedSet<'tcx, List<ProjectionKind>>,
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
@ -99,7 +98,6 @@ impl<'tcx> CtxtInterners<'tcx> {
existential_predicates: Default::default(),
canonical_var_infos: Default::default(),
predicate: Default::default(),
predicate_kint: Default::default(),
predicates: Default::default(),
projs: Default::default(),
place_elems: Default::default(),
@ -1617,7 +1615,6 @@ nop_lift! {type_; Ty<'a> => Ty<'tcx>}
nop_lift! {region; Region<'a> => Region<'tcx>}
nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}
nop_lift! {predicate_kint; &'a PredicateKint<'a> => &'tcx PredicateKint<'tcx>}
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
@ -2030,8 +2027,8 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
}
}
impl<'tcx> Borrow<PredicateKint<'tcx>> for Interned<'tcx, PredicateKint<'tcx>> {
fn borrow<'a>(&'a self) -> &'a PredicateKint<'tcx> {
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
&self.0
}
}
@ -2065,7 +2062,6 @@ macro_rules! direct_interners {
direct_interners! {
region: mk_region(RegionKind),
const_: mk_const(Const<'tcx>),
predicate_kint: intern_predicate_kint(PredicateKint<'tcx>),
}
macro_rules! slice_interners {

View file

@ -201,45 +201,31 @@ impl FlagComputation {
}
}
fn add_predicate(&mut self, pred: &ty::Predicate<'_>) {
self.add_flags(pred.inner.flags);
self.add_exclusive_binder(pred.inner.outer_exclusive_binder);
}
fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
match kind {
ty::PredicateKind::Trait(trait_pred, _constness) => {
let mut computation = FlagComputation::new();
computation.add_substs(trait_pred.skip_binder().trait_ref.substs);
self.add_bound_computation(computation);
self.add_substs(trait_pred.trait_ref.substs);
}
ty::PredicateKind::RegionOutlives(poly_outlives) => {
let mut computation = FlagComputation::new();
let ty::OutlivesPredicate(a, b) = poly_outlives.skip_binder();
computation.add_region(a);
computation.add_region(b);
self.add_bound_computation(computation);
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
self.add_region(a);
self.add_region(b);
}
ty::PredicateKind::TypeOutlives(poly_outlives) => {
let mut computation = FlagComputation::new();
let ty::OutlivesPredicate(ty, region) = poly_outlives.skip_binder();
computation.add_ty(ty);
computation.add_region(region);
self.add_bound_computation(computation);
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
self.add_ty(ty);
self.add_region(region);
}
ty::PredicateKind::Subtype(poly_subtype) => {
let mut computation = FlagComputation::new();
let ty::SubtypePredicate { a_is_expected: _, a, b } = poly_subtype.skip_binder();
computation.add_ty(a);
computation.add_ty(b);
self.add_bound_computation(computation);
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
self.add_ty(a);
self.add_ty(b);
}
&ty::PredicateKind::Projection(projection) => {
let mut computation = FlagComputation::new();
let ty::ProjectionPredicate { projection_ty, ty } = projection.skip_binder();
computation.add_projection_ty(projection_ty);
computation.add_ty(ty);
self.add_bound_computation(computation);
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));
@ -255,6 +241,13 @@ impl FlagComputation {
self.add_const(expected);
self.add_const(found);
}
ty::PredicateKind::ForAll(binder) => {
let mut computation = FlagComputation::new();
computation.add_predicate(binder.skip_binder());
self.add_bound_computation(computation);
}
}
}

View file

@ -1048,6 +1048,36 @@ impl<'tcx> Predicate<'tcx> {
pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
&self.inner.kind
}
/// Skips `PredicateKind::ForAll`.
pub fn ignore_qualifiers(self, tcx: TyCtxt<'tcx>) -> Binder<Predicate<'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),
}
}
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
pub fn potentially_qualified(
self,
tcx: TyCtxt<'tcx>,
qualifier: impl FnOnce(Binder<Predicate<'tcx>>) -> PredicateKind<'tcx>,
) -> Predicate<'tcx> {
if self.has_escaping_bound_vars() {
qualifier(Binder::bind(self)).to_predicate(tcx)
} else {
self
}
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
@ -1065,72 +1095,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
}
}
impl<'tcx> Predicate<'tcx> {
pub fn kint(self, tcx: TyCtxt<'tcx>) -> &'tcx PredicateKint<'tcx> {
// I am efficient
tcx.intern_predicate_kint(match *self.kind() {
PredicateKind::Trait(binder, data) => {
if let Some(simpl) = binder.no_bound_vars() {
PredicateKint::Trait(simpl, data)
} else {
let inner = tcx
.intern_predicate_kint(PredicateKint::Trait(*binder.skip_binder(), data));
PredicateKint::ForAll(Binder::bind(inner))
}
}
PredicateKind::RegionOutlives(binder) => {
if let Some(simpl) = binder.no_bound_vars() {
PredicateKint::RegionOutlives(simpl)
} else {
let inner = tcx.intern_predicate_kint(PredicateKint::RegionOutlives(
*binder.skip_binder(),
));
PredicateKint::ForAll(Binder::bind(inner))
}
}
PredicateKind::TypeOutlives(binder) => {
if let Some(simpl) = binder.no_bound_vars() {
PredicateKint::TypeOutlives(simpl)
} else {
let inner = tcx
.intern_predicate_kint(PredicateKint::TypeOutlives(*binder.skip_binder()));
PredicateKint::ForAll(Binder::bind(inner))
}
}
PredicateKind::Projection(binder) => {
if let Some(simpl) = binder.no_bound_vars() {
PredicateKint::Projection(simpl)
} else {
let inner =
tcx.intern_predicate_kint(PredicateKint::Projection(*binder.skip_binder()));
PredicateKint::ForAll(Binder::bind(inner))
}
}
PredicateKind::WellFormed(arg) => PredicateKint::WellFormed(arg),
PredicateKind::ObjectSafe(def_id) => PredicateKint::ObjectSafe(def_id),
PredicateKind::ClosureKind(def_id, substs, kind) => {
PredicateKint::ClosureKind(def_id, substs, kind)
}
PredicateKind::Subtype(binder) => {
if let Some(simpl) = binder.no_bound_vars() {
PredicateKint::Subtype(simpl)
} else {
let inner =
tcx.intern_predicate_kint(PredicateKint::Subtype(*binder.skip_binder()));
PredicateKint::ForAll(Binder::bind(inner))
}
}
PredicateKind::ConstEvaluatable(def, substs) => {
PredicateKint::ConstEvaluatable(def, substs)
}
PredicateKind::ConstEquate(l, r) => PredicateKint::ConstEquate(l, r),
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(TypeFoldable)]
pub enum PredicateKint<'tcx> {
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
pub enum PredicateKind<'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.
@ -1165,66 +1132,13 @@ pub enum PredicateKint<'tcx> {
Subtype(SubtypePredicate<'tcx>),
/// Constant initializer must evaluate successfully.
ConstEvaluatable(DefId, SubstsRef<'tcx>),
ConstEvaluatable(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
/// Constants must be equal. The first component is the const that is expected.
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
/// `for<'a>: ...`
ForAll(Binder<&'tcx PredicateKint<'tcx>>),
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
pub enum PredicateKind<'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.
///
/// A trait predicate will have `Constness::Const` if it originates
/// from a bound on a `const fn` without the `?const` opt-out (e.g.,
/// `const fn foobar<Foo: Bar>() {}`).
Trait(PolyTraitPredicate<'tcx>, Constness),
/// `where 'a: 'b`
RegionOutlives(PolyRegionOutlivesPredicate<'tcx>),
/// `where T: 'a`
TypeOutlives(PolyTypeOutlivesPredicate<'tcx>),
/// `where <T as TraitRef>::Name == X`, approximately.
/// See the `ProjectionPredicate` struct for details.
Projection(PolyProjectionPredicate<'tcx>),
/// No syntax: `T` well-formed.
WellFormed(GenericArg<'tcx>),
/// Trait must be object-safe.
ObjectSafe(DefId),
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
/// for some substitutions `...` and `T` being a closure type.
/// Satisfied (or refuted) once we know the closure's kind.
ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind),
/// `T1 <: T2`
Subtype(PolySubtypePredicate<'tcx>),
/// Constant initializer must evaluate successfully.
ConstEvaluatable(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
/// Constants must be equal. The first component is the const that is expected.
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
}
impl<'tcx> PredicateKint<'tcx> {
/// Skips `PredicateKint::ForAll`.
pub fn ignore_qualifiers(&'tcx self) -> Binder<&'tcx PredicateKint<'tcx>> {
match self {
&PredicateKint::ForAll(binder) => binder,
pred => Binder::dummy(pred),
}
}
ForAll(Binder<Predicate<'tcx>>),
}
/// The crate outlives map is computed during typeck and contains the
@ -1313,20 +1227,18 @@ impl<'tcx> Predicate<'tcx> {
// this trick achieves that).
let substs = trait_ref.skip_binder().substs;
let kind = match self.kint(tcx) {
PredicateKint::ForAll(binder) => *binder.skip_binder(),
let kind = match self.kind() {
PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
kind => kind,
};
let new = kind.subst(tcx, substs);
let rebound = if new.has_escaping_bound_vars() {
PredicateKint::ForAll(Binder::bind(tcx.intern_predicate_kint(new)))
if new != *kind {
new.to_predicate(tcx).potentially_qualified(tcx, PredicateKind::ForAll)
} else {
new
};
if rebound != *kind { rebound.to_predicate(tcx) } else { self }
self
}
}
}
@ -1451,94 +1363,33 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
}
}
impl ToPredicate<'tcx> for PredicateKint<'tcx> {
#[inline(always)]
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
let (predicate, in_binder) = if let PredicateKint::ForAll(binder) = self {
(*binder.skip_binder(), true)
} else {
(self, false)
};
macro_rules! bind {
($expr:expr) => {
match $expr {
expr => {
if in_binder {
Binder::bind(expr)
} else {
Binder::dummy(expr)
}
}
}
};
}
match *predicate {
PredicateKint::ForAll(_) => bug!("unexpected PredicateKint: {:?}", self),
PredicateKint::Trait(data, ct) => PredicateKind::Trait(bind!(data), ct),
PredicateKint::RegionOutlives(data) => PredicateKind::RegionOutlives(bind!(data)),
PredicateKint::TypeOutlives(data) => PredicateKind::TypeOutlives(bind!(data)),
PredicateKint::Projection(data) => PredicateKind::Projection(bind!(data)),
PredicateKint::WellFormed(arg) => {
if in_binder {
bug!("unexpected ForAll: {:?}", self)
} else {
PredicateKind::WellFormed(arg)
}
}
PredicateKint::ObjectSafe(def_id) => {
if in_binder {
bug!("unexpected ForAll: {:?}", self)
} else {
PredicateKind::ObjectSafe(def_id)
}
}
PredicateKint::ClosureKind(def_id, substs, kind) => {
if in_binder {
bug!("unexpected ForAll: {:?}", self)
} else {
PredicateKind::ClosureKind(def_id, substs, kind)
}
}
PredicateKint::Subtype(data) => PredicateKind::Subtype(bind!(data)),
PredicateKint::ConstEvaluatable(def_id, substs) => {
if in_binder {
bug!("unexpected ForAll: {:?}", self)
} else {
PredicateKind::ConstEvaluatable(def_id, substs)
}
}
PredicateKint::ConstEquate(l, r) => {
if in_binder {
bug!("unexpected ForAll: {:?}", self)
} else {
PredicateKind::ConstEquate(l, r)
}
}
}
.to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
.to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
if let Some(trait_ref) = self.value.no_bound_vars() {
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref }, self.constness)
ConstnessAnd {
value: self.value.map_bound(|trait_ref| ty::TraitPredicate { trait_ref }),
constness: 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)
} else {
ty::PredicateKint::ForAll(self.value.map_bound(|trait_ref| {
tcx.intern_predicate_kint(ty::PredicateKint::Trait(
ty::TraitPredicate { trait_ref },
self.constness,
))
}))
ty::PredicateKind::ForAll(
self.value.map_bound(|pred| {
ty::PredicateKind::Trait(pred, self.constness).to_predicate(tcx)
}),
)
}
.to_predicate(tcx)
}
@ -1547,11 +1398,13 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'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() {
PredicateKint::RegionOutlives(outlives)
PredicateKind::RegionOutlives(outlives)
} else {
ty::PredicateKint::ForAll(self.map_bound(|outlives| {
tcx.intern_predicate_kint(PredicateKint::RegionOutlives(outlives))
}))
ty::PredicateKind::ForAll(
self.map_bound(|outlives| {
PredicateKind::RegionOutlives(outlives).to_predicate(tcx)
}),
)
}
.to_predicate(tcx)
}
@ -1559,45 +1412,68 @@ impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateKind::TypeOutlives(self).to_predicate(tcx)
if let Some(outlives) = self.no_bound_vars() {
PredicateKind::TypeOutlives(outlives)
} else {
ty::PredicateKind::ForAll(
self.map_bound(|outlives| PredicateKind::TypeOutlives(outlives).to_predicate(tcx)),
)
}
.to_predicate(tcx)
}
}
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateKind::Projection(self).to_predicate(tcx)
if let Some(proj) = self.no_bound_vars() {
PredicateKind::Projection(proj)
} else {
ty::PredicateKind::ForAll(
self.map_bound(|proj| PredicateKind::Projection(proj).to_predicate(tcx)),
)
}
.to_predicate(tcx)
}
}
impl<'tcx> Predicate<'tcx> {
pub fn to_opt_poly_trait_ref(self) -> Option<PolyTraitRef<'tcx>> {
match self.kind() {
&PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
| PredicateKind::WellFormed(..)
| PredicateKind::ObjectSafe(..)
| PredicateKind::ClosureKind(..)
| PredicateKind::TypeOutlives(..)
| PredicateKind::ConstEvaluatable(..)
| PredicateKind::ConstEquate(..) => None,
}
pub fn to_opt_poly_trait_ref(self, tcx: TyCtxt<'tcx>) -> Option<PolyTraitRef<'tcx>> {
self.ignore_qualifiers(tcx)
.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()
}
pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
match self.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,
}
pub fn to_opt_type_outlives(
self,
tcx: TyCtxt<'tcx>,
) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
self.ignore_qualifiers(tcx)
.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()
}
}

View file

@ -572,7 +572,7 @@ pub trait PrettyPrinter<'tcx>:
let mut is_sized = false;
p!(write("impl"));
for predicate in bounds.predicates {
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref(self.tcx()) {
// Don't print +Sized, but rather +?Sized if absent.
if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() {
is_sized = true;
@ -2039,6 +2039,9 @@ define_print_and_forward_display! {
print(c2),
write("`"))
}
ty::PredicateKind::ForAll(binder) => {
p!(print(binder))
}
}
}

View file

@ -247,6 +247,7 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
}
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
}
}
}
@ -478,20 +479,18 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
type Lifted = ty::PredicateKind<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self {
ty::PredicateKind::Trait(ref binder, constness) => {
tcx.lift(binder).map(|binder| ty::PredicateKind::Trait(binder, constness))
ty::PredicateKind::Trait(ref data, constness) => {
tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness))
}
ty::PredicateKind::Subtype(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::Subtype)
ty::PredicateKind::Subtype(ref data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
ty::PredicateKind::RegionOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
}
ty::PredicateKind::RegionOutlives(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::RegionOutlives)
ty::PredicateKind::TypeOutlives(ref data) => {
tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
}
ty::PredicateKind::TypeOutlives(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::TypeOutlives)
}
ty::PredicateKind::Projection(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::Projection)
ty::PredicateKind::Projection(ref data) => {
tcx.lift(data).map(ty::PredicateKind::Projection)
}
ty::PredicateKind::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateKind::WellFormed),
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
@ -508,6 +507,9 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
ty::PredicateKind::ConstEquate(c1, c2) => {
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
}
ty::PredicateKind::ForAll(ref binder) => {
tcx.lift(binder).map(ty::PredicateKind::ForAll)
}
}
}
}
@ -1028,17 +1030,6 @@ impl<T: TypeVisitor<'tcx>> PredicateVisitor<'tcx> for T {
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::PredicateKint<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
let new = ty::PredicateKint::super_fold_with(self, folder);
folder.tcx().intern_predicate_kint(new)
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
ty::PredicateKint::super_visit_with(self, visitor)
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v))

View file

@ -895,6 +895,19 @@ impl<T> Binder<T> {
Binder(value)
}
/// Wraps `value` in a binder without actually binding any currently
/// unbound variables.
pub fn wrap_nonbinding(tcx: TyCtxt<'tcx>, value: T) -> Binder<T>
where
T: TypeFoldable<'tcx>,
{
if value.has_escaping_bound_vars() {
Binder::bind(super::fold::shift_vars(tcx, &value, 1))
} else {
Binder::dummy(value)
}
}
/// Skips the binder and returns the "bound" value. This is a
/// risky thing to do because it's easy to get confused about
/// De Bruijn indices and the like. It is usually better to
@ -979,6 +992,15 @@ impl<T> Binder<T> {
}
}
impl<T> Binder<Option<T>> {
pub fn transpose(self) -> Option<Binder<T>> {
match self.0 {
Some(v) => Some(Binder(v)),
None => None,
}
}
}
/// Represents the projection of an associated type. In explicit UFCS
/// form this would be written `<T as Trait<..>>::N`.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]

View file

@ -589,10 +589,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut found = false;
for predicate in bounds.predicates {
if let ty::PredicateKind::TypeOutlives(binder) = predicate.kind() {
if let ty::OutlivesPredicate(_, ty::RegionKind::ReStatic) =
binder.skip_binder()
{
if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
predicate.ignore_qualifiers(self.infcx.tcx).skip_binder().kind()
{
if let ty::RegionKind::ReStatic = r {
found = true;
break;
} else {

View file

@ -274,7 +274,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
// Insert the facts we know from the predicates. Why? Why not.
let param_env = self.param_env;
self.add_outlives_bounds(outlives::explicit_outlives_bounds(param_env));
self.add_outlives_bounds(outlives::explicit_outlives_bounds(self.infcx.tcx, param_env));
// Finally:
// - outlives is reflexive, so `'r: 'r` for every region `'r`

View file

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

View file

@ -24,7 +24,9 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
loop {
let predicates = tcx.predicates_of(current);
for (predicate, _) in predicates.predicates {
match predicate.kind() {
// TODO: forall
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::WellFormed(_)
@ -44,7 +46,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}
match pred.skip_binder().self_ty().kind {
match pred.self_ty().kind {
ty::Param(ref p) => {
// Allow `T: ?const Trait`
if constness == hir::Constness::NotConst

View file

@ -87,16 +87,14 @@ where
fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool {
let ty::GenericPredicates { parent: _, predicates } = predicates;
for (predicate, _span) in predicates {
match predicate.kind() {
ty::PredicateKind::Trait(poly_predicate, _) => {
let ty::TraitPredicate { trait_ref } = poly_predicate.skip_binder();
// This visitor does not care about bound regions.
match predicate.ignore_qualifiers(self.def_id_visitor.tcx()).skip_binder().kind() {
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
if self.visit_trait(trait_ref) {
return true;
}
}
ty::PredicateKind::Projection(poly_predicate) => {
let ty::ProjectionPredicate { projection_ty, ty } =
poly_predicate.skip_binder();
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
if ty.visit_with(self) {
return true;
}
@ -104,8 +102,7 @@ where
return true;
}
}
ty::PredicateKind::TypeOutlives(poly_predicate) => {
let ty::OutlivesPredicate(ty, _region) = poly_predicate.skip_binder();
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
if ty.visit_with(self) {
return true;
}

View file

@ -1154,8 +1154,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
for predicate in &bounds.predicates {
if let ty::PredicateKind::Projection(projection) = predicate.kind() {
if projection.skip_binder().ty.references_error() {
if let ty::PredicateKind::Projection(projection) =
predicate.ignore_qualifiers(tcx).skip_binder().kind()
{
if projection.ty.references_error() {
// No point on adding these obligations since there's a type error involved.
return ty_var;
}
@ -1252,7 +1254,7 @@ crate fn required_region_bounds(
traits::elaborate_predicates(tcx, predicates)
.filter_map(|obligation| {
debug!("required_region_bounds(obligation={:?})", obligation);
match obligation.predicate.kind() {
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Projection(..)
| ty::PredicateKind::Trait(..)
| ty::PredicateKind::Subtype(..)
@ -1262,7 +1264,8 @@ crate fn required_region_bounds(
| ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => None,
ty::PredicateKind::TypeOutlives(predicate) => {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", obligation),
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
// Search for a bound of the form `erased_self_ty
// : 'a`, but be wary of something like `for<'a>
// erased_self_ty : 'a` (we interpret a
@ -1272,7 +1275,6 @@ crate fn required_region_bounds(
// it's kind of a moot point since you could never
// construct such an object, but this seems
// correct even if that code changes).
let ty::OutlivesPredicate(ref t, ref r) = predicate.skip_binder();
if t == &erased_self_ty && !r.has_escaping_bound_vars() {
Some(*r)
} else {

View file

@ -344,8 +344,7 @@ impl AutoTraitFinder<'tcx> {
already_visited.remove(&pred);
self.add_user_pred(
&mut user_computed_preds,
ty::PredicateKind::Trait(pred, hir::Constness::NotConst)
.to_predicate(self.tcx),
pred.without_const().to_predicate(self.tcx),
);
predicates.push_back(pred);
} else {
@ -408,21 +407,23 @@ impl AutoTraitFinder<'tcx> {
/// under which a type implements an auto trait. A trait predicate involving
/// a HRTB means that the type needs to work with any choice of lifetime,
/// not just one specific lifetime (e.g., `'static`).
fn add_user_pred<'c>(
fn add_user_pred(
&self,
user_computed_preds: &mut FxHashSet<ty::Predicate<'c>>,
new_pred: ty::Predicate<'c>,
user_computed_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
new_pred: ty::Predicate<'tcx>,
) {
let mut should_add_new = true;
user_computed_preds.retain(|&old_pred| {
if let (
ty::PredicateKind::Trait(new_trait, _),
ty::PredicateKind::Trait(old_trait, _),
) = (new_pred.kind(), old_pred.kind())
{
) = (
new_pred.ignore_qualifiers(self.tcx).skip_binder().kind(),
old_pred.ignore_qualifiers(self.tcx).skip_binder().kind(),
) {
if new_trait.def_id() == old_trait.def_id() {
let new_substs = new_trait.skip_binder().trait_ref.substs;
let old_substs = old_trait.skip_binder().trait_ref.substs;
let new_substs = new_trait.trait_ref.substs;
let old_substs = old_trait.trait_ref.substs;
if !new_substs.types().eq(old_substs.types()) {
// We can't compare lifetimes if the types are different,
@ -618,11 +619,12 @@ impl AutoTraitFinder<'tcx> {
) -> bool {
let dummy_cause = ObligationCause::dummy();
for (obligation, mut predicate) in nested.map(|o| (o.clone(), o.predicate)) {
let is_new_pred = fresh_preds.insert(self.clean_pred(select.infcx(), predicate));
for obligation in nested {
let is_new_pred =
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate));
// Resolve any inference variables that we can, to help selection succeed
predicate = select.infcx().resolve_vars_if_possible(&predicate);
let predicate = select.infcx().resolve_vars_if_possible(&obligation.predicate);
// We only add a predicate as a user-displayable bound if
// it involves a generic parameter, and doesn't contain
@ -636,17 +638,20 @@ impl AutoTraitFinder<'tcx> {
//
// We check this by calling is_of_param on the relevant types
// from the various possible predicates
match predicate.kind() {
// TODO: forall
match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
&ty::PredicateKind::Trait(p, _) => {
if self.is_param_no_infer(p.skip_binder().trait_ref.substs)
if self.is_param_no_infer(p.trait_ref.substs)
&& !only_projections
&& is_new_pred
{
self.add_user_pred(computed_preds, predicate);
}
predicates.push_back(p);
predicates.push_back(ty::Binder::bind(p));
}
&ty::PredicateKind::Projection(p) => {
let p = ty::Binder::bind(p);
debug!(
"evaluate_nested_obligations: examining projection predicate {:?}",
predicate
@ -772,11 +777,13 @@ impl AutoTraitFinder<'tcx> {
}
}
&ty::PredicateKind::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) => {
let binder = ty::Binder::bind(binder);
match (
binder.no_bound_vars(),
binder.map_bound_ref(|pred| pred.0).no_bound_vars(),

View file

@ -255,9 +255,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.emit();
return;
}
match obligation.predicate.kind() {
ty::PredicateKind::Trait(ref trait_predicate, _) => {
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
// TODO: forall
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::Trait(trait_predicate, _) => {
let trait_predicate = ty::Binder::bind(trait_predicate);
let trait_predicate = self.resolve_vars_if_possible(&trait_predicate);
if self.tcx.sess.has_errors() && trait_predicate.references_error() {
return;
@ -503,14 +509,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
);
trait_pred
});
let unit_obligation = Obligation {
predicate: ty::PredicateKind::Trait(
predicate,
hir::Constness::NotConst,
)
.to_predicate(self.tcx),
..obligation.clone()
};
let unit_obligation =
obligation.with(predicate.without_const().to_predicate(tcx));
if self.predicate_may_hold(&unit_obligation) {
err.note(
"the trait is implemented for `()`. \
@ -526,15 +526,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
err
}
ty::PredicateKind::Subtype(ref predicate) => {
ty::PredicateKind::Subtype(predicate) => {
// Errors for Subtype predicates show up as
// `FulfillmentErrorCode::CodeSubtypeError`,
// not selection error.
span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
}
ty::PredicateKind::RegionOutlives(ref predicate) => {
let predicate = self.resolve_vars_if_possible(predicate);
&ty::PredicateKind::RegionOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let predicate = self.resolve_vars_if_possible(&predicate);
let err = self
.region_outlives_predicate(&obligation.cause, predicate)
.err()
@ -1089,8 +1090,14 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
return true;
}
let (cond, error) = match (cond.kind(), error.kind()) {
(ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => (cond, error),
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
let (cond, error) = match (
cond.ignore_qualifiers(self.tcx).skip_binder().kind(),
error.ignore_qualifiers(self.tcx).skip_binder().kind(),
) {
(ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(error, _)) => {
(cond, ty::Binder::bind(error))
}
_ => {
// FIXME: make this work in other cases too.
return false;
@ -1098,9 +1105,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
};
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
if let ty::PredicateKind::Trait(implication, _) = obligation.predicate.kind() {
if let &ty::PredicateKind::Trait(implication, _) =
obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind()
{
let error = error.to_poly_trait_ref();
let implication = implication.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.
// Eventually I'll need to implement param-env-aware
// `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
@ -1178,12 +1187,14 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
//
// this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message.
if let ty::PredicateKind::Projection(ref data) = predicate.kind() {
if let &ty::PredicateKind::Projection(data) =
predicate.ignore_qualifiers(self.tcx).skip_binder().kind()
{
let mut selcx = SelectionContext::new(self);
let (data, _) = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
infer::LateBoundRegionConversionTime::HigherRankedType,
data,
&ty::Binder::bind(data),
);
let mut obligations = vec![];
let normalized_ty = super::normalize_projection_type(
@ -1470,9 +1481,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
let mut err = match predicate.kind() {
ty::PredicateKind::Trait(ref data, _) => {
let trait_ref = data.to_poly_trait_ref();
// TODO: forall
let mut err = match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
&ty::PredicateKind::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);
@ -1571,6 +1583,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ty::PredicateKind::WellFormed(arg) => {
// TODO: forall
// Same hacky approach as above to avoid deluging user
// with error messages.
if arg.references_error() || self.tcx.sess.has_errors() {
@ -1595,15 +1609,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
// no need to overload user in such cases
return;
}
let SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder();
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(ref data) => {
let trait_ref = data.to_poly_trait_ref(self.tcx);
&ty::PredicateKind::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.skip_binder().ty;
let ty = data.ty;
if predicate.references_error() {
return;
}
@ -1724,16 +1738,16 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
obligation: &PredicateObligation<'tcx>,
) {
let (pred, item_def_id, span) =
match (obligation.predicate.kind(), &obligation.cause.code.peel_derives()) {
match (obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind(), obligation.cause.code.peel_derives()) {
(
ty::PredicateKind::Trait(pred, _),
ObligationCauseCode::BindingObligation(item_def_id, span),
&ObligationCauseCode::BindingObligation(item_def_id, span),
) => (pred, item_def_id, span),
_ => return,
};
let node = match (
self.tcx.hir().get_if_local(*item_def_id),
self.tcx.hir().get_if_local(item_def_id),
Some(pred.def_id()) == self.tcx.lang_items().sized_trait(),
) {
(Some(node), true) => node,
@ -1744,7 +1758,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
None => return,
};
for param in generics.params {
if param.span != *span
if param.span != span
|| param.bounds.iter().any(|bound| {
bound.trait_ref().and_then(|trait_ref| trait_ref.trait_def_id())
== self.tcx.lang_items().sized_trait()

View file

@ -1299,12 +1299,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// the type. The last generator (`outer_generator` below) has information about where the
// bound was introduced. At least one generator should be present for this diagnostic to be
// modified.
let (mut trait_ref, mut target_ty) = match obligation.predicate.kind() {
ty::PredicateKind::Trait(p, _) => {
(Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
}
_ => (None, None),
};
let (mut trait_ref, mut target_ty) =
match obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
ty::PredicateKind::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);

View file

@ -6,7 +6,7 @@ use rustc_errors::ErrorReported;
use rustc_infer::traits::{PolyTraitObligation, TraitEngine, TraitEngineExt as _};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::{self, Binder, Const, ToPredicate, Ty, TypeFoldable};
use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable};
use std::marker::PhantomData;
use super::project;
@ -318,12 +318,12 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
let infcx = self.selcx.infcx();
match obligation.predicate.kint(infcx.tcx) {
ty::PredicateKint::ForAll(binder) => match binder.skip_binder() {
match obligation.predicate.kind() {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder().kind() {
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
rustc_middle::ty::PredicateKint::Trait(trait_ref, _constness) => {
ty::PredicateKind::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(Binder::bind(*trait_ref));
self.process_trait_obligation(
@ -332,7 +332,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
&mut pending_obligation.stalled_on,
)
}
rustc_middle::ty::PredicateKint::Projection(projection) => {
ty::PredicateKind::Projection(projection) => {
let project_obligation = obligation.with(Binder::bind(*projection));
self.process_projection_obligation(
@ -340,22 +340,20 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
&mut pending_obligation.stalled_on,
)
}
rustc_middle::ty::PredicateKint::RegionOutlives(_)
| rustc_middle::ty::PredicateKint::TypeOutlives(_)
| rustc_middle::ty::PredicateKint::WellFormed(_)
| rustc_middle::ty::PredicateKint::ObjectSafe(_)
| rustc_middle::ty::PredicateKint::ClosureKind(..)
| rustc_middle::ty::PredicateKint::Subtype(_)
| rustc_middle::ty::PredicateKint::ConstEvaluatable(..)
| rustc_middle::ty::PredicateKint::ConstEquate(..)
| rustc_middle::ty::PredicateKint::ForAll(_) => {
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.to_predicate(infcx.tcx)),
]))
ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
}
},
ty::PredicateKint::Trait(ref data, _) => {
ty::PredicateKind::Trait(ref data, _) => {
let trait_obligation = obligation.with(Binder::dummy(*data));
self.process_trait_obligation(
@ -365,14 +363,14 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
)
}
&ty::PredicateKint::RegionOutlives(data) => {
&ty::PredicateKind::RegionOutlives(data) => {
match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
Ok(()) => ProcessResult::Changed(vec![]),
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
}
}
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
if self.register_region_obligations {
self.selcx.infcx().register_region_obligation_with_cause(
t_a,
@ -383,7 +381,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
ProcessResult::Changed(vec![])
}
ty::PredicateKint::Projection(ref data) => {
ty::PredicateKind::Projection(ref data) => {
let project_obligation = obligation.with(Binder::dummy(*data));
self.process_projection_obligation(
@ -392,7 +390,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
)
}
&ty::PredicateKint::ObjectSafe(trait_def_id) => {
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) {
ProcessResult::Error(CodeSelectionError(Unimplemented))
} else {
@ -400,7 +398,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKint::ClosureKind(_, closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
@ -413,7 +411,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKint::WellFormed(arg) => {
&ty::PredicateKind::WellFormed(arg) => {
match wf::obligations(
self.selcx.infcx(),
obligation.param_env,
@ -430,7 +428,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKint::Subtype(subtype) => {
&ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate(
&obligation.cause,
obligation.param_env,
@ -456,7 +454,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
&ty::PredicateKint::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
match self.selcx.infcx().const_eval_resolve(
obligation.param_env,
def_id,
@ -469,7 +467,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}
ty::PredicateKint::ConstEquate(c1, c2) => {
ty::PredicateKind::ConstEquate(c1, c2) => {
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
let stalled_on = &mut pending_obligation.stalled_on;

View file

@ -237,7 +237,7 @@ fn do_normalize_predicates<'tcx>(
// We can use the `elaborated_env` here; the region code only
// cares about declarations like `'a: 'b`.
let outlives_env = OutlivesEnvironment::new(elaborated_env);
let outlives_env = OutlivesEnvironment::new(tcx, elaborated_env);
infcx.resolve_regions_and_report_errors(
region_context,
@ -328,7 +328,7 @@ pub fn normalize_param_env_or_error<'tcx>(
// This works fairly well because trait matching does not actually care about param-env
// TypeOutlives predicates - these are normally used by regionck.
let outlives_predicates: Vec<_> = predicates
.drain_filter(|predicate| match predicate.kind() {
.drain_filter(|predicate| match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::TypeOutlives(..) => true,
_ => false,
})

View file

@ -245,14 +245,11 @@ fn predicates_reference_self(
.iter()
.map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
.filter_map(|(predicate, &sp)| {
match predicate.kind() {
// TODO: forall
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Trait(ref data, _) => {
// In the case of a trait predicate, we can skip the "self" type.
if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) {
Some(sp)
} else {
None
}
if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
}
ty::PredicateKind::Projection(ref data) => {
// And similarly for projections. This should be redundant with
@ -267,10 +264,7 @@ fn predicates_reference_self(
//
// This is ALT2 in issue #56288, see that for discussion of the
// possible alternatives.
if data.skip_binder().projection_ty.trait_ref(tcx).substs[1..]
.iter()
.any(has_self_ty)
{
if data.projection_ty.trait_ref(tcx).substs[1..].iter().any(has_self_ty) {
Some(sp)
} else {
None
@ -284,6 +278,7 @@ fn predicates_reference_self(
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => None,
ty::PredicateKind::ForAll(..) => bug!("unexpected predicate: {:?}", predicate),
}
})
.collect()
@ -305,10 +300,10 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let predicates = tcx.predicates_of(def_id);
let predicates = predicates.instantiate_identity(tcx).predicates;
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
match obligation.predicate.kind() {
// TODO: forall
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Trait(ref trait_pred, _) => {
trait_pred.def_id() == sized_def_id
&& trait_pred.skip_binder().self_ty().is_param(0)
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
}
ty::PredicateKind::Projection(..)
| ty::PredicateKind::Subtype(..)
@ -319,6 +314,9 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
| ty::PredicateKind::TypeOutlives(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => false,
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
}
})
}
@ -404,7 +402,7 @@ fn virtual_call_violation_for_method<'tcx>(
// A trait object can't claim to live more than the concrete type,
// so outlives predicates will always hold.
.cloned()
.filter(|(p, _)| p.to_opt_type_outlives().is_none())
.filter(|(p, _)| p.to_opt_type_outlives(tcx).is_none())
.collect::<Vec<_>>()
// Do a shallow visit so that `contains_illegal_self_type_reference`
// may apply it's custom visiting.

View file

@ -664,23 +664,25 @@ fn prune_cache_value_obligations<'a, 'tcx>(
let mut obligations: Vec<_> = result
.obligations
.iter()
.filter(|obligation| match obligation.predicate.kind() {
// 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
// projection can help resolve any of the type
// variables found in `result.value` -- but we just
// check for any type variables here, for fear of
// indirect obligations (e.g., we project to `?0`,
// but we have `T: Foo<X = ?1>` and `?1: Bar<X =
// ?0>`).
ty::PredicateKind::Projection(ref data) => {
infcx.unresolved_type_vars(&data.ty()).is_some()
}
.filter(|obligation| {
match obligation.predicate.ignore_qualifiers(infcx.tcx).skip_binder().kind() {
// 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
// projection can help resolve any of the type
// variables found in `result.value` -- but we just
// check for any type variables here, for fear of
// indirect obligations (e.g., we project to `?0`,
// but we have `T: Foo<X = ?1>` and `?1: Bar<X =
// ?0>`).
&ty::PredicateKind::Projection(data) => {
infcx.unresolved_type_vars(&ty::Binder::bind(data.ty)).is_some()
}
// We are only interested in `T: Foo<X = U>` predicates, whre
// `U` references one of `unresolved_type_vars`. =)
_ => false,
// We are only interested in `T: Foo<X = U>` predicates, whre
// `U` references one of `unresolved_type_vars`. =)
_ => false,
}
})
.cloned()
.collect();
@ -931,7 +933,11 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx();
for predicate in env_predicates {
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
if let &ty::PredicateKind::Projection(data) = predicate.kind() {
// TODO: forall
if let &ty::PredicateKind::Projection(data) =
predicate.ignore_qualifiers(infcx.tcx).skip_binder().kind()
{
let data = ty::Binder::bind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
let is_match = same_def_id
@ -1221,13 +1227,17 @@ fn confirm_object_candidate<'cx, 'tcx>(
// select only those projections that are actually projecting an
// item with the correct name
let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() {
&ty::PredicateKind::Projection(data)
if data.projection_def_id() == obligation.predicate.item_def_id =>
{
Some(data)
// TODO: forall
let env_predicates = env_predicates.filter_map(|o| {
match o.predicate.ignore_qualifiers(selcx.tcx()).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,
}
_ => None,
});
// select those with a relevant trait-ref

View file

@ -15,10 +15,12 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
// `&T`, accounts for about 60% percentage of the predicates
// we have to prove. No need to canonicalize and all that for
// such cases.
if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind() {
if let ty::PredicateKind::Trait(trait_ref, _) =
key.value.predicate.ignore_qualifiers(tcx).skip_binder().kind()
{
if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
if trait_ref.def_id() == sized_def_id {
if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) {
if trait_ref.self_ty().is_trivially_sized(tcx) {
return Some(());
}
}

View file

@ -181,6 +181,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
stack: &TraitObligationStack<'o, 'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
let tcx = self.tcx();
debug!("assemble_candidates_from_caller_bounds({:?})", stack.obligation);
let all_bounds = stack
@ -188,7 +189,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.param_env
.caller_bounds()
.iter()
.filter_map(|o| o.to_opt_poly_trait_ref());
.filter_map(move |o| o.to_opt_poly_trait_ref(tcx));
// Micro-optimization: filter out predicates relating to different traits.
let matching_bounds =

View file

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

View file

@ -35,7 +35,9 @@ use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::fast_reject;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{
self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
};
use rustc_span::symbol::sym;
use std::cell::{Cell, RefCell};
@ -406,14 +408,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
None => self.check_recursion_limit(&obligation, &obligation)?,
}
match obligation.predicate.kind() {
// TODO: forall
match obligation.predicate.ignore_qualifiers(self.tcx()).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::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) => {
let p = ty::Binder::bind(p);
// Does this code ever run?
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
Some(Ok(InferOk { mut obligations, .. })) => {
@ -456,6 +464,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
&ty::PredicateKind::Projection(data) => {
let data = ty::Binder::bind(data);
let project_obligation = obligation.with(data);
match project::poly_project_and_unify_type(self, &project_obligation) {
Ok(Some(mut subobligations)) => {
@ -669,10 +678,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// if the regions match exactly.
let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
let tcx = self.tcx();
let cycle = cycle.map(|stack| {
ty::PredicateKind::Trait(stack.obligation.predicate, hir::Constness::NotConst)
.to_predicate(tcx)
});
let cycle =
cycle.map(|stack| stack.obligation.predicate.without_const().to_predicate(tcx));
if self.coinductive_match(cycle) {
debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref);
Some(EvaluatedToOk)
@ -786,7 +793,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
let result = match predicate.kind() {
let result = match predicate.ignore_qualifiers(self.tcx()).skip_binder().kind() {
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
_ => false,
};

View file

@ -497,7 +497,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>
Vec::with_capacity(predicates.len() + types_without_default_bounds.len());
for (p, _) in predicates {
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref(tcx) {
if Some(poly_trait_ref.def_id()) == sized_trait {
types_without_default_bounds.remove(poly_trait_ref.self_ty().skip_binder());
continue;

View file

@ -120,7 +120,7 @@ impl<'tcx> TraitAliasExpander<'tcx> {
let items = predicates.predicates.iter().rev().filter_map(|(pred, span)| {
pred.subst_supertrait(tcx, &trait_ref)
.to_opt_poly_trait_ref()
.to_opt_poly_trait_ref(tcx)
.map(|trait_ref| item.clone_and_push(trait_ref, *span))
});
debug!("expand_trait_aliases: items={:?}", items.clone());
@ -170,6 +170,7 @@ impl Iterator for SupertraitDefIds<'tcx> {
type Item = DefId;
fn next(&mut self) -> Option<DefId> {
let tcx = self.tcx;
let def_id = self.stack.pop()?;
let predicates = self.tcx.super_predicates_of(def_id);
let visited = &mut self.visited;
@ -177,7 +178,7 @@ impl Iterator for SupertraitDefIds<'tcx> {
predicates
.predicates
.iter()
.filter_map(|(pred, _)| pred.to_opt_poly_trait_ref())
.filter_map(move |(pred, _)| pred.to_opt_poly_trait_ref(tcx))
.map(|trait_ref| trait_ref.def_id())
.filter(|&super_def_id| visited.insert(super_def_id)),
);

View file

@ -88,33 +88,33 @@ pub fn predicate_obligations<'a, 'tcx>(
infcx: &InferCtxt<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_id: hir::HirId,
predicate: &'tcx ty::PredicateKint<'tcx>,
predicate: &'_ ty::Predicate<'tcx>,
span: Span,
) -> Vec<traits::PredicateObligation<'tcx>> {
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
match predicate {
ty::PredicateKint::ForAll(binder) => {
match predicate.kind() {
ty::PredicateKind::ForAll(binder) => {
// 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);
return predicate_obligations(infcx, param_env, body_id, binder.skip_binder(), span);
}
ty::PredicateKint::Trait(t, _) => {
ty::PredicateKind::Trait(t, _) => {
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
}
ty::PredicateKint::RegionOutlives(..) => {}
&ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
ty::PredicateKind::RegionOutlives(..) => {}
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
wf.compute(ty.into());
}
ty::PredicateKint::Projection(t) => {
ty::PredicateKind::Projection(t) => {
wf.compute_projection(t.projection_ty);
wf.compute(t.ty.into());
}
&ty::PredicateKint::WellFormed(arg) => {
&ty::PredicateKind::WellFormed(arg) => {
wf.compute(arg);
}
ty::PredicateKint::ObjectSafe(_) => {}
ty::PredicateKint::ClosureKind(..) => {}
&ty::PredicateKint::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
ty::PredicateKind::ObjectSafe(_) => {}
ty::PredicateKind::ClosureKind(..) => {}
&ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
wf.compute(a.into());
wf.compute(b.into());
}
@ -126,7 +126,7 @@ pub fn predicate_obligations<'a, 'tcx>(
wf.compute(arg);
}
}
&ty::PredicateKint::ConstEquate(c1, c2) => {
&ty::PredicateKind::ConstEquate(c1, c2) => {
wf.compute(c1.into());
wf.compute(c2.into());
}
@ -178,7 +178,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
trait_ref: &ty::TraitRef<'tcx>,
item: Option<&hir::Item<'tcx>>,
cause: &mut traits::ObligationCause<'tcx>,
pred: &ty::Predicate<'_>,
pred: &ty::Predicate<'tcx>,
mut trait_assoc_items: impl Iterator<Item = &'tcx ty::AssocItem>,
) {
debug!(
@ -194,15 +194,16 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::TyAlias(ty) => ty.span,
_ => impl_item_ref.span,
};
match pred.kind() {
// It is fine to skip the binder as we don't care about regions here.
match pred.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Projection(proj) => {
// The obligation comes not from the current `impl` nor the `trait` being implemented,
// but rather from a "second order" obligation, where an associated type has a
// projection coming from another associated type. See
// `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and
// `traits-assoc-type-in-supertrait-bad.rs`.
let kind = &proj.ty().skip_binder().kind;
if let ty::Projection(projection_ty) = kind {
if let ty::Projection(projection_ty) = proj.ty.kind {
let trait_assoc_item = tcx.associated_item(projection_ty.item_def_id);
if let Some(impl_item_span) =
items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span)
@ -215,11 +216,9 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
// 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);
if let ty::Projection(ty::ProjectionTy { item_def_id, .. }) =
&pred.skip_binder().self_ty().kind
{
if let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = pred.self_ty().kind {
if let Some(impl_item_span) = trait_assoc_items
.find(|i| i.def_id == *item_def_id)
.find(|i| i.def_id == item_def_id)
.and_then(|trait_assoc_item| {
items.iter().find(|i| i.ident == trait_assoc_item.ident).map(fix_span)
})
@ -270,7 +269,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let extend = |obligation: traits::PredicateObligation<'tcx>| {
let mut cause = cause.clone();
if let Some(parent_trait_ref) = obligation.predicate.to_opt_poly_trait_ref() {
if let Some(parent_trait_ref) = obligation.predicate.to_opt_poly_trait_ref(tcx) {
let derived_cause = traits::DerivedObligationCause {
parent_trait_ref,
parent_code: Rc::new(obligation.cause.code.clone()),
@ -318,7 +317,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
traits::Obligation::new(
new_cause,
param_env,
ty::PredicateKint::WellFormed(arg).to_predicate(tcx),
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
)
}),
);
@ -397,7 +396,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.push(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateKint::WellFormed(resolved_constant.into())
ty::PredicateKind::WellFormed(resolved_constant.into())
.to_predicate(self.tcx()),
));
}
@ -483,7 +482,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.push(traits::Obligation::new(
cause,
param_env,
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(rty, r))
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
.to_predicate(self.tcx()),
));
}

View file

@ -78,10 +78,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
let clauses = self.environment.into_iter().filter_map(|clause| match clause {
ChalkEnvironmentClause::Predicate(predicate) => {
match predicate.kind() {
ty::PredicateKind::Trait(predicate, _) => {
// FIXME(chalk): forall
match predicate.ignore_qualifiers(interner.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
&ty::PredicateKind::Trait(predicate, _) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
collect_bound_vars(interner, interner.tcx, &predicate);
Some(
chalk_ir::ProgramClauseData(chalk_ir::Binders::new(
@ -124,9 +127,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
}
// FIXME(chalk): need to add TypeOutlives
ty::PredicateKind::TypeOutlives(_) => None,
ty::PredicateKind::Projection(predicate) => {
&ty::PredicateKind::Projection(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
collect_bound_vars(interner, interner.tcx, &predicate);
Some(
chalk_ir::ProgramClauseData(chalk_ir::Binders::new(
@ -181,8 +185,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
match self.kind() {
ty::PredicateKind::Trait(predicate, _) => predicate.lower_into(interner),
// FIXME(chalk): forall
match self.ignore_qualifiers(interner.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
&ty::PredicateKind::Trait(predicate, _) => {
ty::Binder::bind(predicate).lower_into(interner)
}
ty::PredicateKind::RegionOutlives(predicate) => {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
@ -205,7 +213,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
ty::PredicateKind::TypeOutlives(_predicate) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
}
ty::PredicateKind::Projection(predicate) => predicate.lower_into(interner),
&ty::PredicateKind::Projection(predicate) => {
ty::Binder::bind(predicate).lower_into(interner)
}
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
GenericArgKind::Type(ty) => match ty.kind {
// FIXME(chalk): In Chalk, a placeholder is WellFormed if it
@ -532,8 +542,11 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
match &self.kind() {
ty::PredicateKind::Trait(predicate, _) => {
// FIXME(chalk): forall
match self.ignore_qualifiers(interner.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
&ty::PredicateKind::Trait(predicate, _) => {
let predicate = &ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
@ -632,7 +645,9 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
}
(0..parameters.len()).for_each(|i| {
parameters.get(&(i as u32)).expect(&format!("Skipped bound var index `{:?}`.", i));
parameters
.get(&(i as u32))
.or_else(|| bug!("Skipped bound var index: ty={:?}, parameters={:?}", ty, parameters));
});
let binders = chalk_ir::VariableKinds::from(interner, parameters.into_iter().map(|(_, v)| v));

View file

@ -95,6 +95,7 @@ fn compute_implied_outlives_bounds<'tcx>(
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
assert!(!obligation.has_escaping_bound_vars());
match obligation.predicate.kind() {
ty::PredicateKind::ForAll(..) => vec![],
ty::PredicateKind::Trait(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Projection(..)
@ -102,28 +103,21 @@ fn compute_implied_outlives_bounds<'tcx>(
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => vec![],
&ty::PredicateKind::WellFormed(arg) => {
wf_args.push(arg);
vec![]
}
ty::PredicateKind::RegionOutlives(ref data) => match data.no_bound_vars() {
None => vec![],
Some(ty::OutlivesPredicate(r_a, r_b)) => {
vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
}
},
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
}
ty::PredicateKind::TypeOutlives(ref data) => match data.no_bound_vars() {
None => vec![],
Some(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::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)
}
}
}));
}

View file

@ -27,7 +27,9 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
// always only region relations, and we are about to
// erase those anyway:
debug_assert_eq!(
normalized_obligations.iter().find(|p| not_outlives_predicate(&p.predicate)),
normalized_obligations
.iter()
.find(|p| not_outlives_predicate(tcx, &p.predicate)),
None,
);
@ -39,9 +41,11 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
})
}
fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
match p.kind() {
fn not_outlives_predicate(tcx: TyCtxt<'tcx>, p: &ty::Predicate<'tcx>) -> bool {
// TODO: forall
match p.ignore_qualifiers(tcx).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(..)

View file

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

View file

@ -1705,8 +1705,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"conv_object_ty_poly_trait_ref: observing object predicate `{:?}`",
obligation.predicate
);
match obligation.predicate.kind() {
ty::PredicateKind::Trait(pred, _) => {
// TODO: forall
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
&ty::PredicateKind::Trait(pred, _) => {
let pred = ty::Binder::bind(pred);
associated_types.entry(span).or_default().extend(
tcx.associated_items(pred.def_id())
.in_definition_order()
@ -1715,6 +1718,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);
}
&ty::PredicateKind::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.
let references_self =
@ -2094,7 +2098,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|| {
traits::transitive_bounds(
tcx,
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
predicates.iter().filter_map(move |(p, _)| p.to_opt_poly_trait_ref(tcx)),
)
},
|| param_name.to_string(),

View file

@ -206,11 +206,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
obligation.predicate
);
if let &ty::PredicateKind::Projection(proj_predicate) = obligation.predicate.kind()
if let &ty::PredicateKind::Projection(proj_predicate) =
obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind()
{
// Given a Projection predicate, we can potentially infer
// the complete signature.
self.deduce_sig_from_projection(Some(obligation.cause.span), proj_predicate)
self.deduce_sig_from_projection(
Some(obligation.cause.span),
ty::Binder::bind(proj_predicate),
)
} else {
None
}
@ -627,8 +631,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// where R is the return type we are expecting. This type `T`
// will be our output.
let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
if let &ty::PredicateKind::Projection(proj_predicate) = obligation.predicate.kind() {
self.deduce_future_output_from_projection(obligation.cause.span, proj_predicate)
if let &ty::PredicateKind::Projection(proj_predicate) =
obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind()
{
self.deduce_future_output_from_projection(
obligation.cause.span,
ty::Binder::bind(proj_predicate),
)
} else {
None
}

View file

@ -582,24 +582,25 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
while !queue.is_empty() {
let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation);
let trait_pred = match obligation.predicate.kind() {
&ty::PredicateKind::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>
{
if unsize_did == trait_pred.def_id() {
let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty();
if let ty::Tuple(..) = unsize_ty.kind {
debug!("coerce_unsized: found unsized tuple coercion");
has_unsized_tuple_coercion = true;
let trait_pred =
match obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
&ty::PredicateKind::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>
{
if unsize_did == trait_pred.def_id() {
let unsize_ty = trait_pred.trait_ref.substs[1].expect_ty();
if let ty::Tuple(..) = unsize_ty.kind {
debug!("coerce_unsized: found unsized tuple coercion");
has_unsized_tuple_coercion = true;
}
}
ty::Binder::bind(trait_pred)
}
trait_pred
}
_ => {
coercion.obligations.push(obligation);
continue;
}
};
_ => {
coercion.obligations.push(obligation);
continue;
}
};
match selcx.select(&obligation.with(trait_pred)) {
// Uncertain or unimplemented.
Ok(None) => {

View file

@ -127,7 +127,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
// it did the wrong thing, so I chose to preserve existing
// behavior, since it ought to be simply more
// conservative. -nmatsakis
let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
let outlives_env = OutlivesEnvironment::new(infcx.tcx, ty::ParamEnv::empty());
infcx.resolve_regions_and_report_errors(
drop_impl_did.to_def_id(),
@ -226,12 +226,15 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
// could be extended easily also to the other `Predicate`.
let predicate_matches_closure = |p: Predicate<'tcx>| {
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
match (predicate.kind(), p.kind()) {
match (
predicate.ignore_qualifiers(tcx).skip_binder().kind(),
p.ignore_qualifiers(tcx).skip_binder().kind(),
) {
(&ty::PredicateKind::Trait(a, _), &ty::PredicateKind::Trait(b, _)) => {
relator.relate(a, b).is_ok()
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
}
(&ty::PredicateKind::Projection(a), &ty::PredicateKind::Projection(b)) => {
relator.relate(a, b).is_ok()
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
}
_ => predicate == p,
}

View file

@ -447,21 +447,27 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
};
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
.filter_map(|obligation| match obligation.predicate.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))
// We don't care about regions here.
.filter_map(|obligation| {
match obligation.predicate.ignore_qualifiers(self.tcx).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,
}
_ => None,
})
.find_map(|(trait_pred, span)| match trait_pred.skip_binder().self_ty().kind {
.find_map(|(trait_pred, span)| match trait_pred.self_ty().kind {
ty::Dynamic(..) => Some(span),
_ => None,
})

View file

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

View file

@ -795,6 +795,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
let tcx = self.tcx;
// FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);

View file

@ -570,12 +570,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let mut type_params = FxHashMap::default();
let mut bound_spans = vec![];
let mut collect_type_param_suggestions =
|self_ty: Ty<'_>, parent_pred: &ty::Predicate<'_>, obligation: &str| {
if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) =
(&self_ty.kind, parent_pred.kind())
{
if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind {
let mut collect_type_param_suggestions = {
// We need to move `tcx` while only borrowing the rest,
// 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_qualifiers(tcx).skip_binder().kind(),
) {
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))
});
@ -597,7 +602,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
};
}
};
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
let msg = format!(
"doesn't satisfy `{}`",
@ -625,8 +631,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
let mut format_pred = |pred: ty::Predicate<'tcx>| {
match pred.kind() {
ty::PredicateKind::Projection(pred) => {
// TODO: forall
match pred.ignore_qualifiers(tcx).skip_binder().kind() {
&ty::PredicateKind::Projection(pred) => {
let pred = ty::Binder::bind(pred);
// `<Foo as Iterator>::Item = String`.
let trait_ref =
pred.skip_binder().projection_ty.trait_ref(self.tcx);
@ -644,7 +652,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bound_span_label(trait_ref.self_ty(), &obligation, &quiet);
Some((obligation, trait_ref.self_ty()))
}
ty::PredicateKind::Trait(poly_trait_ref, _) => {
&ty::PredicateKind::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();
let path = p.print_only_trait_path();
@ -950,12 +959,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this isn't perfect (that is, there are cases when
// implementing a trait would be legal but is rejected
// here).
unsatisfied_predicates.iter().all(|(p, _)| match p.kind() {
// 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) => p.item_def_id() == info.def_id,
_ => false,
unsatisfied_predicates.iter().all(|(p, _)| {
match p.ignore_qualifiers(self.tcx).skip_binder().kind() {
// 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) => {
p.projection_ty.item_def_id == info.def_id
}
_ => false,
}
}) && (type_is_local || info.def_id.is_local())
&& self
.associated_item(info.def_id, item_name, Namespace::ValueNS)

View file

@ -2392,26 +2392,28 @@ fn missing_items_err(
}
/// Resugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
fn bounds_from_generic_predicates(
tcx: TyCtxt<'_>,
predicates: ty::GenericPredicates<'_>,
fn bounds_from_generic_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: ty::GenericPredicates<'tcx>,
) -> (String, String) {
let mut types: FxHashMap<Ty<'_>, Vec<DefId>> = FxHashMap::default();
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
let mut projections = vec![];
for (predicate, _) in predicates.predicates {
debug!("predicate {:?}", predicate);
match predicate.kind() {
// TODO: forall (we could keep the current behavior and just skip binders eagerly,
// not sure if we want to though)
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Trait(trait_predicate, _) => {
let entry = types.entry(trait_predicate.skip_binder().self_ty()).or_default();
let def_id = trait_predicate.skip_binder().def_id();
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() {
// Type params are `Sized` by default, do not add that restriction to the list
// if it is a positive requirement.
entry.push(trait_predicate.skip_binder().def_id());
entry.push(trait_predicate.def_id());
}
}
ty::PredicateKind::Projection(projection_pred) => {
projections.push(projection_pred);
projections.push(ty::Binder::bind(projection_pred));
}
_ => {}
}
@ -2456,11 +2458,11 @@ fn bounds_from_generic_predicates(
}
/// Return placeholder code for the given function.
fn fn_sig_suggestion(
tcx: TyCtxt<'_>,
sig: ty::FnSig<'_>,
fn fn_sig_suggestion<'tcx>(
tcx: TyCtxt<'tcx>,
sig: ty::FnSig<'tcx>,
ident: Ident,
predicates: ty::GenericPredicates<'_>,
predicates: ty::GenericPredicates<'tcx>,
assoc: &ty::AssocItem,
) -> String {
let args = sig
@ -3612,7 +3614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_predicate(traits::Obligation::new(
cause,
self.param_env,
ty::PredicateKint::WellFormed(arg).to_predicate(self.tcx),
ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx),
));
}
@ -3893,29 +3895,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.borrow()
.pending_obligations()
.into_iter()
.filter_map(move |obligation| match obligation.predicate.kind() {
ty::PredicateKind::Projection(ref data) => {
Some((data.to_poly_trait_ref(self.tcx), obligation))
// TODO: forall
.filter_map(move |obligation| {
match obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => {
bug!("unexpected predicate: {:?}", obligation.predicate)
}
&ty::PredicateKind::Projection(data) => {
Some((ty::Binder::bind(data).to_poly_trait_ref(self.tcx), obligation))
}
&ty::PredicateKind::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,
// N.B., this predicate is created by breaking down a
// `ClosureType: FnFoo()` predicate, where
// `ClosureType` represents some `Closure`. It can't
// possibly be referring to the current closure,
// because we haven't produced the `Closure` for
// 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::PredicateKind::Trait(ref data, _) => {
Some((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,
// N.B., this predicate is created by breaking down a
// `ClosureType: FnFoo()` predicate, where
// `ClosureType` represents some `Closure`. It can't
// possibly be referring to the current closure,
// because we haven't produced the `Closure` for
// 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,
})
.filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root))
}
@ -4225,7 +4233,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// the corresponding argument's expression span instead of the `fn` call path span.
fn point_at_arg_instead_of_call_if_possible(
&self,
errors: &mut Vec<traits::FulfillmentError<'_>>,
errors: &mut Vec<traits::FulfillmentError<'tcx>>,
final_arg_types: &[(usize, Ty<'tcx>, Ty<'tcx>)],
call_sp: Span,
args: &'tcx [hir::Expr<'tcx>],
@ -4244,7 +4252,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
continue;
}
if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate.kind() {
if let ty::PredicateKind::Trait(predicate, _) =
error.obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind()
{
// Collect the argument position for all arguments that could have caused this
// `FulfillmentError`.
let mut referenced_in = final_arg_types
@ -4255,7 +4265,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.resolve_vars_if_possible(&ty);
// We walk the argument type because the argument's type could have
// been `Option<T>`, but the `FulfillmentError` references `T`.
if ty.walk().any(|arg| arg == predicate.skip_binder().self_ty().into()) {
if ty.walk().any(|arg| arg == predicate.self_ty().into()) {
Some(i)
} else {
None
@ -4284,15 +4294,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// instead of the `fn` call path span.
fn point_at_type_arg_instead_of_call_if_possible(
&self,
errors: &mut Vec<traits::FulfillmentError<'_>>,
errors: &mut Vec<traits::FulfillmentError<'tcx>>,
call_expr: &'tcx hir::Expr<'tcx>,
) {
if let hir::ExprKind::Call(path, _) = &call_expr.kind {
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.kind()
if let ty::PredicateKind::Trait(predicate, _) = error
.obligation
.predicate
.ignore_qualifiers(self.tcx)
.skip_binder()
.kind()
{
// If any of the type arguments in this path segment caused the
// `FullfillmentError`, point at its span (#61860).
@ -4313,7 +4327,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
let ty = AstConv::ast_ty_to_ty(self, hir_ty);
let ty = self.resolve_vars_if_possible(&ty);
if ty == predicate.skip_binder().self_ty() {
if ty == predicate.self_ty() {
error.obligation.cause.make_mut().span = hir_ty.span;
}
}
@ -5365,12 +5379,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_def_id,
};
let predicate =
ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate {
projection_ty,
ty: expected,
}))
.to_predicate(self.tcx);
let predicate = ty::PredicateKind::Projection(ty::ProjectionPredicate {
projection_ty,
ty: expected,
})
.to_predicate(self.tcx)
.potentially_qualified(self.tcx, ty::PredicateKind::ForAll);
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
debug!("suggest_missing_await: trying obligation {:?}", obligation);

View file

@ -194,7 +194,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> RegionCtxt<'a, 'tcx> {
let region_scope_tree = fcx.tcx.region_scope_tree(subject);
let outlives_environment = OutlivesEnvironment::new(param_env);
let outlives_environment = OutlivesEnvironment::new(fcx.tcx, param_env);
RegionCtxt {
fcx,
region_scope_tree,

View file

@ -828,8 +828,8 @@ fn check_where_clauses<'tcx, 'fcx>(
debug!("check_where_clauses: predicates={:?}", predicates.predicates);
assert_eq!(predicates.predicates.len(), predicates.spans.len());
let wf_obligations =
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(&p, &sp)| {
traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p.kint(tcx), sp)
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(p, &sp)| {
traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, sp)
});
for obligation in wf_obligations.chain(default_obligations) {

View file

@ -292,7 +292,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
}
// Finally, resolve all regions.
let outlives_env = OutlivesEnvironment::new(param_env);
let outlives_env = OutlivesEnvironment::new(tcx, param_env);
infcx.resolve_regions_and_report_errors(
impl_did.to_def_id(),
&outlives_env,
@ -549,7 +549,7 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI
}
// Finally, resolve all regions.
let outlives_env = OutlivesEnvironment::new(param_env);
let outlives_env = OutlivesEnvironment::new(tcx, param_env);
infcx.resolve_regions_and_report_errors(impl_did, &outlives_env, RegionckMode::default());
CoerceUnsizedInfo { custom_kind: kind }

View file

@ -552,10 +552,8 @@ fn type_param_predicates(
let extra_predicates = extend.into_iter().chain(
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
.into_iter()
.filter(|(predicate, _)| match predicate.kind() {
ty::PredicateKind::Trait(ref data, _) => {
data.skip_binder().self_ty().is_param(index)
}
.filter(|(predicate, _)| match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index),
_ => false,
}),
);
@ -1006,7 +1004,8 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
// which will, in turn, reach indirect supertraits.
for &(pred, span) in superbounds {
debug!("superbound: {:?}", pred);
if let ty::PredicateKind::Trait(bound, _) = pred.kind() {
if let ty::PredicateKind::Trait(bound, _) = pred.ignore_qualifiers(tcx).skip_binder().kind()
{
tcx.at(span).super_predicates_of(bound.def_id());
}
}
@ -1961,9 +1960,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
&hir::GenericBound::Outlives(ref lifetime) => {
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region));
predicates.push((
ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx),
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region))
.to_predicate(tcx)
.potentially_qualified(tcx, ty::PredicateKind::ForAll),
lifetime.span,
))
}
@ -1980,9 +1980,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
}
_ => bug!(),
};
let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
let pred = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(icx.tcx);
(ty::PredicateKind::RegionOutlives(pred).to_predicate(icx.tcx), span)
(pred.potentially_qualified(icx.tcx, ty::PredicateKind::ForAll), span)
}))
}
@ -2110,8 +2111,10 @@ fn predicates_from_bound<'tcx>(
}
hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region));
vec![(ty::PredicateKind::TypeOutlives(pred).to_predicate(astconv.tcx()), lifetime.span)]
let pred = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
.to_predicate(astconv.tcx())
.potentially_qualified(astconv.tcx(), ty::PredicateKind::ForAll);
vec![(pred, lifetime.span)]
}
}
}

View file

@ -180,11 +180,11 @@ pub fn setup_constraining_predicates<'tcx>(
changed = false;
for j in i..predicates.len() {
if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0.kind() {
// Note that we can skip binder here because the impl
// trait ref never contains any late-bound regions.
let projection = poly_projection.skip_binder();
// 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_qualifiers(tcx).skip_binder().kind()
{
// Special case: watch out for some kind of sneaky attempt
// to project out an associated type defined by this very
// trait.

View file

@ -163,7 +163,7 @@ fn get_impl_substs<'tcx>(
let impl2_substs = translate_substs(infcx, param_env, impl1_def_id, impl1_substs, impl2_node);
// Conservatively use an empty `ParamEnv`.
let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
let outlives_env = OutlivesEnvironment::new(tcx, ty::ParamEnv::empty());
infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env, RegionckMode::default());
let impl2_substs = match infcx.fully_resolve(&impl2_substs) {
Ok(s) => s,
@ -198,9 +198,11 @@ fn unconstrained_parent_impl_substs<'tcx>(
// the functions in `cgp` add the constrained parameters to a list of
// unconstrained parameters.
for (predicate, _) in impl_generic_predicates.predicates.iter() {
if let ty::PredicateKind::Projection(proj) = predicate.kind() {
let projection_ty = proj.skip_binder().projection_ty;
let projected_ty = proj.skip_binder().ty;
if let ty::PredicateKind::Projection(proj) =
predicate.ignore_qualifiers(tcx).skip_binder().kind()
{
let projection_ty = proj.projection_ty;
let projected_ty = proj.ty;
let unbound_trait_ref = projection_ty.trait_ref(tcx);
if Some(unbound_trait_ref) == impl_trait_ref {
@ -359,7 +361,7 @@ fn check_predicates<'tcx>(
fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, span: Span) {
debug!("can_specialize_on(predicate = {:?})", predicate);
match predicate.kind() {
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
// Global predicates are either always true or always false, so we
// are fine to specialize on.
_ if predicate.is_global() => (),
@ -392,7 +394,8 @@ fn trait_predicate_kind<'tcx>(
tcx: TyCtxt<'tcx>,
predicate: ty::Predicate<'tcx>,
) -> Option<TraitSpecializationKind> {
match predicate.kind() {
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
Some(tcx.trait_def(pred.def_id()).specialization_kind)
}

View file

@ -29,9 +29,12 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
// process predicates and convert to `RequiredPredicates` entry, see below
for &(predicate, span) in predicates.predicates {
match predicate.kind() {
// TODO: forall
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
ty::PredicateKind::ForAll(_) => bug!("unepected predicate: {:?}", predicate),
ty::PredicateKind::TypeOutlives(predicate) => {
let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder();
let OutlivesPredicate(ref ty, ref reg) = predicate;
insert_outlives_predicate(
tcx,
(*ty).into(),
@ -42,7 +45,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
}
ty::PredicateKind::RegionOutlives(predicate) => {
let OutlivesPredicate(ref reg1, ref reg2) = predicate.skip_binder();
let OutlivesPredicate(ref reg1, ref reg2) = predicate;
insert_outlives_predicate(
tcx,
(*reg1).into(),

View file

@ -85,17 +85,17 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|(ty::OutlivesPredicate(kind1, region2), &span)| {
match kind1.unpack() {
GenericArgKind::Type(ty1) => Some((
ty::PredicateKind::TypeOutlives(ty::Binder::bind(
ty::OutlivesPredicate(ty1, region2),
))
.to_predicate(tcx),
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
.to_predicate(tcx)
.potentially_qualified(tcx, ty::PredicateKind::ForAll),
span,
)),
GenericArgKind::Lifetime(region1) => Some((
ty::PredicateKind::RegionOutlives(ty::Binder::bind(
ty::OutlivesPredicate(region1, region2),
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
region1, region2,
))
.to_predicate(tcx),
.to_predicate(tcx)
.potentially_qualified(tcx, ty::PredicateKind::ForAll),
span,
)),
GenericArgKind::Const(_) => {

View file

@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.iter()
.filter(|p| {
!orig_bounds.contains(p)
|| match p.kind() {
|| match p.ignore_qualifiers().skip_binder().kind() {
ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
_ => false,
}

View file

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