directly contain PredicateAtom
in PredicateKind::ForAll
This commit is contained in:
parent
d8cf8ba5f7
commit
cd9743b4d4
10 changed files with 162 additions and 179 deletions
|
@ -531,11 +531,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
let predicate = match k1.unpack() {
|
let predicate = match k1.unpack() {
|
||||||
GenericArgKind::Lifetime(r1) => {
|
GenericArgKind::Lifetime(r1) => {
|
||||||
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
|
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
|
||||||
.to_predicate(self.tcx)
|
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(t1) => {
|
GenericArgKind::Type(t1) => {
|
||||||
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
|
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
|
||||||
.to_predicate(self.tcx)
|
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(..) => {
|
GenericArgKind::Const(..) => {
|
||||||
// Consts cannot outlive one another, so we don't expect to
|
// Consts cannot outlive one another, so we don't expect to
|
||||||
|
|
|
@ -201,55 +201,54 @@ 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<'_>) {
|
fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
|
||||||
match kind {
|
match kind {
|
||||||
ty::PredicateKind::ForAll(binder) => {
|
ty::PredicateKind::ForAll(binder) => {
|
||||||
let mut computation = FlagComputation::new();
|
let mut computation = FlagComputation::new();
|
||||||
|
|
||||||
computation.add_predicate(binder.skip_binder());
|
computation.add_predicate_atom(binder.skip_binder());
|
||||||
|
|
||||||
self.add_bound_computation(computation);
|
self.add_bound_computation(computation);
|
||||||
}
|
}
|
||||||
&ty::PredicateKind::Atom(atom) => match atom {
|
&ty::PredicateKind::Atom(atom) => self.add_predicate_atom(atom),
|
||||||
ty::PredicateAtom::Trait(trait_pred, _constness) => {
|
}
|
||||||
self.add_substs(trait_pred.trait_ref.substs);
|
}
|
||||||
}
|
|
||||||
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
|
fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) {
|
||||||
self.add_region(a);
|
match atom {
|
||||||
self.add_region(b);
|
ty::PredicateAtom::Trait(trait_pred, _constness) => {
|
||||||
}
|
self.add_substs(trait_pred.trait_ref.substs);
|
||||||
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
|
}
|
||||||
self.add_ty(ty);
|
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||||
self.add_region(region);
|
self.add_region(a);
|
||||||
}
|
self.add_region(b);
|
||||||
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
|
}
|
||||||
self.add_ty(a);
|
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
|
||||||
self.add_ty(b);
|
self.add_ty(ty);
|
||||||
}
|
self.add_region(region);
|
||||||
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
|
}
|
||||||
self.add_projection_ty(projection_ty);
|
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
|
||||||
self.add_ty(ty);
|
self.add_ty(a);
|
||||||
}
|
self.add_ty(b);
|
||||||
ty::PredicateAtom::WellFormed(arg) => {
|
}
|
||||||
self.add_substs(slice::from_ref(&arg));
|
ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
|
||||||
}
|
self.add_projection_ty(projection_ty);
|
||||||
ty::PredicateAtom::ObjectSafe(_def_id) => {}
|
self.add_ty(ty);
|
||||||
ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
|
}
|
||||||
self.add_substs(substs);
|
ty::PredicateAtom::WellFormed(arg) => {
|
||||||
}
|
self.add_substs(slice::from_ref(&arg));
|
||||||
ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
|
}
|
||||||
self.add_substs(substs);
|
ty::PredicateAtom::ObjectSafe(_def_id) => {}
|
||||||
}
|
ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
|
||||||
ty::PredicateAtom::ConstEquate(expected, found) => {
|
self.add_substs(substs);
|
||||||
self.add_const(expected);
|
}
|
||||||
self.add_const(found);
|
ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
|
||||||
}
|
self.add_substs(substs);
|
||||||
},
|
}
|
||||||
|
ty::PredicateAtom::ConstEquate(expected, found) => {
|
||||||
|
self.add_const(expected);
|
||||||
|
self.add_const(found);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1053,8 +1053,9 @@ impl<'tcx> Predicate<'tcx> {
|
||||||
///
|
///
|
||||||
/// Note that this method panics in case this predicate has unbound variables.
|
/// Note that this method panics in case this predicate has unbound variables.
|
||||||
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
|
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
|
||||||
|
// TODO no_escaping_vars
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
&PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
|
&PredicateKind::ForAll(binder) => binder.skip_binder(),
|
||||||
&ty::PredicateKind::Atom(atom) => atom,
|
&ty::PredicateKind::Atom(atom) => atom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1066,33 +1067,17 @@ impl<'tcx> Predicate<'tcx> {
|
||||||
/// to end up at the wrong binding level.
|
/// to end up at the wrong binding level.
|
||||||
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
|
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
&PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
|
&PredicateKind::ForAll(binder) => binder.skip_binder(),
|
||||||
&ty::PredicateKind::Atom(atom) => atom,
|
&ty::PredicateKind::Atom(atom) => atom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
|
pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
&PredicateKind::ForAll(binder) => binder.map_bound(|inner| match inner.kind() {
|
&PredicateKind::ForAll(binder) => binder,
|
||||||
ty::PredicateKind::ForAll(_) => bug!("unexpect forall"),
|
|
||||||
&ty::PredicateKind::Atom(atom) => atom,
|
|
||||||
}),
|
|
||||||
&ty::PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
|
&ty::PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
|
|
||||||
pub fn potentially_quantified(
|
|
||||||
self,
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
qualifier: impl FnOnce(Binder<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> {
|
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||||
|
@ -1114,7 +1099,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||||
#[derive(HashStable, TypeFoldable)]
|
#[derive(HashStable, TypeFoldable)]
|
||||||
pub enum PredicateKind<'tcx> {
|
pub enum PredicateKind<'tcx> {
|
||||||
/// `for<'a>: ...`
|
/// `for<'a>: ...`
|
||||||
ForAll(Binder<Predicate<'tcx>>),
|
ForAll(Binder<PredicateAtom<'tcx>>),
|
||||||
|
|
||||||
Atom(PredicateAtom<'tcx>),
|
Atom(PredicateAtom<'tcx>),
|
||||||
}
|
}
|
||||||
|
@ -1162,6 +1147,22 @@ pub enum PredicateAtom<'tcx> {
|
||||||
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
|
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> PredicateAtom<'tcx> {
|
||||||
|
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
|
||||||
|
pub fn potentially_quantified(
|
||||||
|
self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
|
||||||
|
) -> Predicate<'tcx> {
|
||||||
|
if self.has_escaping_bound_vars() {
|
||||||
|
qualifier(Binder::bind(self))
|
||||||
|
} else {
|
||||||
|
PredicateKind::Atom(self)
|
||||||
|
}
|
||||||
|
.to_predicate(tcx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The crate outlives map is computed during typeck and contains the
|
/// The crate outlives map is computed during typeck and contains the
|
||||||
/// outlives of every item in the local crate. You should not use it
|
/// outlives of every item in the local crate. You should not use it
|
||||||
/// directly, because to do so will make your pass dependent on the
|
/// directly, because to do so will make your pass dependent on the
|
||||||
|
@ -1249,11 +1250,7 @@ impl<'tcx> Predicate<'tcx> {
|
||||||
let substs = trait_ref.skip_binder().substs;
|
let substs = trait_ref.skip_binder().substs;
|
||||||
let pred = self.skip_binders();
|
let pred = self.skip_binders();
|
||||||
let new = pred.subst(tcx, substs);
|
let new = pred.subst(tcx, substs);
|
||||||
if new != pred {
|
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
|
||||||
new.to_predicate(tcx).potentially_quantified(tcx, PredicateKind::ForAll)
|
|
||||||
} else {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1381,6 +1378,7 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
|
||||||
impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
|
impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||||
|
debug_assert!(!self.has_escaping_bound_vars(), "excaping bound vars for {:?}", self);
|
||||||
tcx.mk_predicate(ty::PredicateKind::Atom(*self))
|
tcx.mk_predicate(ty::PredicateKind::Atom(*self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1408,9 +1406,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
|
||||||
ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
|
ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
|
||||||
} else {
|
} else {
|
||||||
ty::PredicateKind::ForAll(
|
ty::PredicateKind::ForAll(
|
||||||
self.value.map_bound(|pred| {
|
self.value.map_bound(|pred| ty::PredicateAtom::Trait(pred, self.constness)),
|
||||||
ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.to_predicate(tcx)
|
.to_predicate(tcx)
|
||||||
}
|
}
|
||||||
|
@ -1423,9 +1419,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
|
||||||
PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
|
PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
|
||||||
} else {
|
} else {
|
||||||
ty::PredicateKind::ForAll(
|
ty::PredicateKind::ForAll(
|
||||||
self.map_bound(|outlives| {
|
self.map_bound(|outlives| PredicateAtom::RegionOutlives(outlives)),
|
||||||
PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.to_predicate(tcx)
|
.to_predicate(tcx)
|
||||||
}
|
}
|
||||||
|
@ -1438,7 +1432,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
|
||||||
PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)
|
PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)
|
||||||
} else {
|
} else {
|
||||||
ty::PredicateKind::ForAll(
|
ty::PredicateKind::ForAll(
|
||||||
self.map_bound(|outlives| PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)),
|
self.map_bound(|outlives| PredicateAtom::TypeOutlives(outlives)),
|
||||||
)
|
)
|
||||||
.to_predicate(tcx)
|
.to_predicate(tcx)
|
||||||
}
|
}
|
||||||
|
@ -1450,10 +1444,8 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
|
||||||
if let Some(proj) = self.no_bound_vars() {
|
if let Some(proj) = self.no_bound_vars() {
|
||||||
PredicateAtom::Projection(proj).to_predicate(tcx)
|
PredicateAtom::Projection(proj).to_predicate(tcx)
|
||||||
} else {
|
} else {
|
||||||
ty::PredicateKind::ForAll(
|
ty::PredicateKind::ForAll(self.map_bound(|proj| PredicateAtom::Projection(proj)))
|
||||||
self.map_bound(|proj| PredicateAtom::Projection(proj).to_predicate(tcx)),
|
.to_predicate(tcx)
|
||||||
)
|
|
||||||
.to_predicate(tcx)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2013,43 +2013,45 @@ define_print_and_forward_display! {
|
||||||
|
|
||||||
ty::Predicate<'tcx> {
|
ty::Predicate<'tcx> {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
&ty::PredicateKind::Atom(atom) => match atom {
|
&ty::PredicateKind::Atom(atom) => p!(print(atom)),
|
||||||
ty::PredicateAtom::Trait(ref data, constness) => {
|
ty::PredicateKind::ForAll(binder) => p!(print(binder)),
|
||||||
if let hir::Constness::Const = constness {
|
}
|
||||||
p!(write("const "));
|
}
|
||||||
}
|
|
||||||
p!(print(data))
|
ty::PredicateAtom<'tcx> {
|
||||||
}
|
match *self {
|
||||||
ty::PredicateAtom::Subtype(predicate) => p!(print(predicate)),
|
ty::PredicateAtom::Trait(ref data, constness) => {
|
||||||
ty::PredicateAtom::RegionOutlives(predicate) => p!(print(predicate)),
|
if let hir::Constness::Const = constness {
|
||||||
ty::PredicateAtom::TypeOutlives(predicate) => p!(print(predicate)),
|
p!(write("const "));
|
||||||
ty::PredicateAtom::Projection(predicate) => p!(print(predicate)),
|
|
||||||
ty::PredicateAtom::WellFormed(arg) => p!(print(arg), write(" well-formed")),
|
|
||||||
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
|
|
||||||
p!(write("the trait `"),
|
|
||||||
print_def_path(trait_def_id, &[]),
|
|
||||||
write("` is object-safe"))
|
|
||||||
}
|
|
||||||
ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
|
|
||||||
p!(write("the closure `"),
|
|
||||||
print_value_path(closure_def_id, &[]),
|
|
||||||
write("` implements the trait `{}`", kind))
|
|
||||||
}
|
|
||||||
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
|
|
||||||
p!(write("the constant `"),
|
|
||||||
print_value_path(def.did, substs),
|
|
||||||
write("` can be evaluated"))
|
|
||||||
}
|
|
||||||
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
|
||||||
p!(write("the constant `"),
|
|
||||||
print(c1),
|
|
||||||
write("` equals `"),
|
|
||||||
print(c2),
|
|
||||||
write("`"))
|
|
||||||
}
|
}
|
||||||
|
p!(print(data))
|
||||||
}
|
}
|
||||||
ty::PredicateKind::ForAll(binder) => {
|
ty::PredicateAtom::Subtype(predicate) => p!(print(predicate)),
|
||||||
p!(print(binder))
|
ty::PredicateAtom::RegionOutlives(predicate) => p!(print(predicate)),
|
||||||
|
ty::PredicateAtom::TypeOutlives(predicate) => p!(print(predicate)),
|
||||||
|
ty::PredicateAtom::Projection(predicate) => p!(print(predicate)),
|
||||||
|
ty::PredicateAtom::WellFormed(arg) => p!(print(arg), write(" well-formed")),
|
||||||
|
ty::PredicateAtom::ObjectSafe(trait_def_id) => {
|
||||||
|
p!(write("the trait `"),
|
||||||
|
print_def_path(trait_def_id, &[]),
|
||||||
|
write("` is object-safe"))
|
||||||
|
}
|
||||||
|
ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
|
||||||
|
p!(write("the closure `"),
|
||||||
|
print_value_path(closure_def_id, &[]),
|
||||||
|
write("` implements the trait `{}`", kind))
|
||||||
|
}
|
||||||
|
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
|
||||||
|
p!(write("the constant `"),
|
||||||
|
print_value_path(def.did, substs),
|
||||||
|
write("` can be evaluated"))
|
||||||
|
}
|
||||||
|
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
||||||
|
p!(write("the constant `"),
|
||||||
|
print(c1),
|
||||||
|
write("` equals `"),
|
||||||
|
print(c2),
|
||||||
|
write("`"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rustc_errors::ErrorReported;
|
||||||
use rustc_infer::traits::{PolyTraitObligation, TraitEngine, TraitEngineExt as _};
|
use rustc_infer::traits::{PolyTraitObligation, TraitEngine, TraitEngineExt as _};
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::ty::error::ExpectedFound;
|
use rustc_middle::ty::error::ExpectedFound;
|
||||||
|
use rustc_middle::ty::ToPredicate;
|
||||||
use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable};
|
use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
|
|
@ -93,45 +93,40 @@ pub fn predicate_obligations<'a, 'tcx>(
|
||||||
) -> Vec<traits::PredicateObligation<'tcx>> {
|
) -> Vec<traits::PredicateObligation<'tcx>> {
|
||||||
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
||||||
|
|
||||||
match predicate.kind() {
|
// It's ok to skip the binder here because wf code is prepared for it
|
||||||
ty::PredicateKind::ForAll(binder) => {
|
match predicate.skip_binders() {
|
||||||
// It's ok to skip the binder here because wf code is prepared for it
|
ty::PredicateAtom::Trait(t, _) => {
|
||||||
return predicate_obligations(infcx, param_env, body_id, binder.skip_binder(), span);
|
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
|
||||||
}
|
}
|
||||||
&ty::PredicateKind::Atom(atom) => match atom {
|
ty::PredicateAtom::RegionOutlives(..) => {}
|
||||||
ty::PredicateAtom::Trait(t, _) => {
|
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
|
||||||
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
|
wf.compute(ty.into());
|
||||||
}
|
}
|
||||||
ty::PredicateAtom::RegionOutlives(..) => {}
|
ty::PredicateAtom::Projection(t) => {
|
||||||
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
|
wf.compute_projection(t.projection_ty);
|
||||||
wf.compute(ty.into());
|
wf.compute(t.ty.into());
|
||||||
}
|
}
|
||||||
ty::PredicateAtom::Projection(t) => {
|
ty::PredicateAtom::WellFormed(arg) => {
|
||||||
wf.compute_projection(t.projection_ty);
|
wf.compute(arg);
|
||||||
wf.compute(t.ty.into());
|
}
|
||||||
}
|
ty::PredicateAtom::ObjectSafe(_) => {}
|
||||||
ty::PredicateAtom::WellFormed(arg) => {
|
ty::PredicateAtom::ClosureKind(..) => {}
|
||||||
|
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
|
||||||
|
wf.compute(a.into());
|
||||||
|
wf.compute(b.into());
|
||||||
|
}
|
||||||
|
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
|
||||||
|
let obligations = wf.nominal_obligations(def.did, substs);
|
||||||
|
wf.out.extend(obligations);
|
||||||
|
|
||||||
|
for arg in substs.iter() {
|
||||||
wf.compute(arg);
|
wf.compute(arg);
|
||||||
}
|
}
|
||||||
ty::PredicateAtom::ObjectSafe(_) => {}
|
}
|
||||||
ty::PredicateAtom::ClosureKind(..) => {}
|
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
||||||
ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
|
wf.compute(c1.into());
|
||||||
wf.compute(a.into());
|
wf.compute(c2.into());
|
||||||
wf.compute(b.into());
|
}
|
||||||
}
|
|
||||||
ty::PredicateAtom::ConstEvaluatable(def, substs) => {
|
|
||||||
let obligations = wf.nominal_obligations(def.did, substs);
|
|
||||||
wf.out.extend(obligations);
|
|
||||||
|
|
||||||
for arg in substs.iter() {
|
|
||||||
wf.compute(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
|
||||||
wf.compute(c1.into());
|
|
||||||
wf.compute(c2.into());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wf.normalize()
|
wf.normalize()
|
||||||
|
|
|
@ -798,24 +798,28 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
// FIXME: do we want to commit to this behavior for param bounds?
|
// FIXME: do we want to commit to this behavior for param bounds?
|
||||||
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
|
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
|
||||||
|
|
||||||
let bounds = self.param_env.caller_bounds().iter().map(ty::Predicate::skip_binders).filter_map(|predicate| match predicate
|
let bounds =
|
||||||
{
|
self.param_env.caller_bounds().iter().map(ty::Predicate::skip_binders).filter_map(
|
||||||
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
|predicate| match predicate {
|
||||||
match trait_predicate.trait_ref.self_ty().kind {
|
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
||||||
ty::Param(ref p) if *p == param_ty => Some(ty::Binder::bind(trait_predicate.trait_ref)),
|
match trait_predicate.trait_ref.self_ty().kind {
|
||||||
_ => None,
|
ty::Param(ref p) if *p == param_ty => {
|
||||||
}
|
Some(ty::Binder::bind(trait_predicate.trait_ref))
|
||||||
}
|
}
|
||||||
ty::PredicateAtom::Subtype(..)
|
_ => None,
|
||||||
| ty::PredicateAtom::Projection(..)
|
}
|
||||||
| ty::PredicateAtom::RegionOutlives(..)
|
}
|
||||||
| ty::PredicateAtom::WellFormed(..)
|
ty::PredicateAtom::Subtype(..)
|
||||||
| ty::PredicateAtom::ObjectSafe(..)
|
| ty::PredicateAtom::Projection(..)
|
||||||
| ty::PredicateAtom::ClosureKind(..)
|
| ty::PredicateAtom::RegionOutlives(..)
|
||||||
| ty::PredicateAtom::TypeOutlives(..)
|
| ty::PredicateAtom::WellFormed(..)
|
||||||
| ty::PredicateAtom::ConstEvaluatable(..)
|
| ty::PredicateAtom::ObjectSafe(..)
|
||||||
| ty::PredicateAtom::ConstEquate(..) => None,
|
| ty::PredicateAtom::ClosureKind(..)
|
||||||
});
|
| ty::PredicateAtom::TypeOutlives(..)
|
||||||
|
| ty::PredicateAtom::ConstEvaluatable(..)
|
||||||
|
| ty::PredicateAtom::ConstEquate(..) => None,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
|
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
|
||||||
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);
|
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);
|
||||||
|
|
|
@ -2939,9 +2939,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
predicates: tcx.arena.alloc_from_iter(
|
predicates: tcx.arena.alloc_from_iter(
|
||||||
self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
||||||
match predicate.skip_binders() {
|
match predicate.skip_binders() {
|
||||||
ty::PredicateAtom::Trait(data, _)
|
ty::PredicateAtom::Trait(data, _) if data.self_ty().is_param(index) => {
|
||||||
if data.self_ty().is_param(index) =>
|
|
||||||
{
|
|
||||||
// HACK(eddyb) should get the original `Span`.
|
// HACK(eddyb) should get the original `Span`.
|
||||||
let span = tcx.def_span(def_id);
|
let span = tcx.def_span(def_id);
|
||||||
Some((predicate, span))
|
Some((predicate, span))
|
||||||
|
@ -5373,7 +5371,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
projection_ty,
|
projection_ty,
|
||||||
ty: expected,
|
ty: expected,
|
||||||
})
|
})
|
||||||
.to_predicate(self.tcx)
|
|
||||||
.potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
|
.potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
|
||||||
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
|
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
|
||||||
|
|
||||||
|
|
|
@ -1961,7 +1961,6 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||||
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
|
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
|
||||||
predicates.push((
|
predicates.push((
|
||||||
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
|
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
|
||||||
.to_predicate(tcx)
|
|
||||||
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
||||||
lifetime.span,
|
lifetime.span,
|
||||||
))
|
))
|
||||||
|
@ -1979,8 +1978,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||||
}
|
}
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
};
|
};
|
||||||
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
|
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2));
|
||||||
.to_predicate(icx.tcx);
|
|
||||||
|
|
||||||
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
|
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
|
||||||
}))
|
}))
|
||||||
|
@ -2111,7 +2109,6 @@ fn predicates_from_bound<'tcx>(
|
||||||
hir::GenericBound::Outlives(ref lifetime) => {
|
hir::GenericBound::Outlives(ref lifetime) => {
|
||||||
let region = astconv.ast_region_to_region(lifetime, None);
|
let region = astconv.ast_region_to_region(lifetime, None);
|
||||||
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
|
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
|
||||||
.to_predicate(astconv.tcx())
|
|
||||||
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
|
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
|
||||||
vec![(pred, lifetime.span)]
|
vec![(pred, lifetime.span)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
|
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -90,7 +90,6 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|
||||||
match kind1.unpack() {
|
match kind1.unpack() {
|
||||||
GenericArgKind::Type(ty1) => Some((
|
GenericArgKind::Type(ty1) => Some((
|
||||||
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
|
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
|
||||||
.to_predicate(tcx)
|
|
||||||
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
|
@ -98,7 +97,6 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|
||||||
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
|
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
|
||||||
region1, region2,
|
region1, region2,
|
||||||
))
|
))
|
||||||
.to_predicate(tcx)
|
|
||||||
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue