1
Fork 0

make ty::Predicate carry a ClosureSubsts

This commit is contained in:
Niko Matsakis 2017-11-08 08:50:59 -05:00
parent 0ac8542abc
commit decf3d33d0
8 changed files with 25 additions and 20 deletions

View file

@ -236,8 +236,9 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::Predicate<'gcx> {
ty::Predicate::ObjectSafe(def_id) => { ty::Predicate::ObjectSafe(def_id) => {
def_id.hash_stable(hcx, hasher); def_id.hash_stable(hcx, hasher);
} }
ty::Predicate::ClosureKind(def_id, closure_kind) => { ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
def_id.hash_stable(hcx, hasher); def_id.hash_stable(hcx, hasher);
closure_substs.hash_stable(hcx, hasher);
closure_kind.hash_stable(hcx, hasher); closure_kind.hash_stable(hcx, hasher);
} }
ty::Predicate::ConstEvaluatable(def_id, substs) => { ty::Predicate::ConstEvaluatable(def_id, substs) => {

View file

@ -643,7 +643,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
violations) violations)
} }
ty::Predicate::ClosureKind(closure_def_id, kind) => { ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
let found_kind = self.closure_kind(closure_def_id).unwrap(); let found_kind = self.closure_kind(closure_def_id).unwrap();
let closure_span = self.tcx.hir.span_if_local(closure_def_id).unwrap(); let closure_span = self.tcx.hir.span_if_local(closure_def_id).unwrap();
let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap(); let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap();

View file

@ -438,7 +438,7 @@ fn process_predicate<'a, 'gcx, 'tcx>(
} }
} }
ty::Predicate::ClosureKind(closure_def_id, kind) => { ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
match selcx.infcx().closure_kind(closure_def_id) { match selcx.infcx().closure_kind(closure_def_id) {
Some(closure_kind) => { Some(closure_kind) => {
if closure_kind.extends(kind) { if closure_kind.extends(kind) {

View file

@ -718,7 +718,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
} }
} }
ty::Predicate::ClosureKind(closure_def_id, kind) => { ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
match self.infcx.closure_kind(closure_def_id) { match self.infcx.closure_kind(closure_def_id) {
Some(closure_kind) => { Some(closure_kind) => {
if closure_kind.extends(kind) { if closure_kind.extends(kind) {
@ -2726,7 +2726,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
obligations.push(Obligation::new( obligations.push(Obligation::new(
obligation.cause.clone(), obligation.cause.clone(),
obligation.param_env, obligation.param_env,
ty::Predicate::ClosureKind(closure_def_id, kind))); ty::Predicate::ClosureKind(closure_def_id, substs, kind)));
Ok(VtableClosureData { Ok(VtableClosureData {
closure_def_id, closure_def_id,

View file

@ -43,8 +43,8 @@ fn anonymize_predicate<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
ty::Predicate::ObjectSafe(data) => ty::Predicate::ObjectSafe(data) =>
ty::Predicate::ObjectSafe(data), ty::Predicate::ObjectSafe(data),
ty::Predicate::ClosureKind(closure_def_id, kind) => ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) =>
ty::Predicate::ClosureKind(closure_def_id, kind), ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind),
ty::Predicate::Subtype(ref data) => ty::Predicate::Subtype(ref data) =>
ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data)), ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data)),

View file

@ -896,7 +896,7 @@ pub enum Predicate<'tcx> {
/// No direct syntax. May be thought of as `where T : FnFoo<...>` /// No direct syntax. May be thought of as `where T : FnFoo<...>`
/// for some substitutions `...` and T being a closure type. /// for some substitutions `...` and T being a closure type.
/// Satisfied (or refuted) once we know the closure's kind. /// Satisfied (or refuted) once we know the closure's kind.
ClosureKind(DefId, ClosureKind), ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind),
/// `T1 <: T2` /// `T1 <: T2`
Subtype(PolySubtypePredicate<'tcx>), Subtype(PolySubtypePredicate<'tcx>),
@ -999,8 +999,8 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
Predicate::WellFormed(data.subst(tcx, substs)), Predicate::WellFormed(data.subst(tcx, substs)),
Predicate::ObjectSafe(trait_def_id) => Predicate::ObjectSafe(trait_def_id) =>
Predicate::ObjectSafe(trait_def_id), Predicate::ObjectSafe(trait_def_id),
Predicate::ClosureKind(closure_def_id, kind) => Predicate::ClosureKind(closure_def_id, closure_substs, kind) =>
Predicate::ClosureKind(closure_def_id, kind), Predicate::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind),
Predicate::ConstEvaluatable(def_id, const_substs) => Predicate::ConstEvaluatable(def_id, const_substs) =>
Predicate::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)), Predicate::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)),
} }
@ -1182,8 +1182,8 @@ impl<'tcx> Predicate<'tcx> {
ty::Predicate::ObjectSafe(_trait_def_id) => { ty::Predicate::ObjectSafe(_trait_def_id) => {
vec![] vec![]
} }
ty::Predicate::ClosureKind(_closure_def_id, _kind) => { ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => {
vec![] closure_substs.substs.types().collect()
} }
ty::Predicate::ConstEvaluatable(_, substs) => { ty::Predicate::ConstEvaluatable(_, substs) => {
substs.types().collect() substs.types().collect()

View file

@ -211,8 +211,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
ty::Predicate::WellFormed(ty) => { ty::Predicate::WellFormed(ty) => {
tcx.lift(&ty).map(ty::Predicate::WellFormed) tcx.lift(&ty).map(ty::Predicate::WellFormed)
} }
ty::Predicate::ClosureKind(closure_def_id, kind) => { ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
Some(ty::Predicate::ClosureKind(closure_def_id, kind)) tcx.lift(&closure_substs)
.map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
closure_substs,
kind))
} }
ty::Predicate::ObjectSafe(trait_def_id) => { ty::Predicate::ObjectSafe(trait_def_id) => {
Some(ty::Predicate::ObjectSafe(trait_def_id)) Some(ty::Predicate::ObjectSafe(trait_def_id))
@ -966,8 +969,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
ty::Predicate::Projection(binder.fold_with(folder)), ty::Predicate::Projection(binder.fold_with(folder)),
ty::Predicate::WellFormed(data) => ty::Predicate::WellFormed(data) =>
ty::Predicate::WellFormed(data.fold_with(folder)), ty::Predicate::WellFormed(data.fold_with(folder)),
ty::Predicate::ClosureKind(closure_def_id, kind) => ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) =>
ty::Predicate::ClosureKind(closure_def_id, kind), ty::Predicate::ClosureKind(closure_def_id, closure_substs.fold_with(folder), kind),
ty::Predicate::ObjectSafe(trait_def_id) => ty::Predicate::ObjectSafe(trait_def_id) =>
ty::Predicate::ObjectSafe(trait_def_id), ty::Predicate::ObjectSafe(trait_def_id),
ty::Predicate::ConstEvaluatable(def_id, substs) => ty::Predicate::ConstEvaluatable(def_id, substs) =>
@ -984,7 +987,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor), ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor),
ty::Predicate::Projection(ref binder) => binder.visit_with(visitor), ty::Predicate::Projection(ref binder) => binder.visit_with(visitor),
ty::Predicate::WellFormed(data) => data.visit_with(visitor), ty::Predicate::WellFormed(data) => data.visit_with(visitor),
ty::Predicate::ClosureKind(_closure_def_id, _kind) => false, ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) =>
closure_substs.visit_with(visitor),
ty::Predicate::ObjectSafe(_trait_def_id) => false, ty::Predicate::ObjectSafe(_trait_def_id) => false,
ty::Predicate::ConstEvaluatable(_def_id, substs) => substs.visit_with(visitor), ty::Predicate::ConstEvaluatable(_def_id, substs) => substs.visit_with(visitor),
} }

View file

@ -1257,7 +1257,7 @@ define_print! {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
write!(f, "the trait `{}` is object-safe", tcx.item_path_str(trait_def_id)) write!(f, "the trait `{}` is object-safe", tcx.item_path_str(trait_def_id))
}), }),
ty::Predicate::ClosureKind(closure_def_id, kind) => ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) =>
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
write!(f, "the closure `{}` implements the trait `{}`", write!(f, "the closure `{}` implements the trait `{}`",
tcx.item_path_str(closure_def_id), kind) tcx.item_path_str(closure_def_id), kind)
@ -1281,8 +1281,8 @@ define_print! {
ty::Predicate::ObjectSafe(trait_def_id) => { ty::Predicate::ObjectSafe(trait_def_id) => {
write!(f, "ObjectSafe({:?})", trait_def_id) write!(f, "ObjectSafe({:?})", trait_def_id)
} }
ty::Predicate::ClosureKind(closure_def_id, kind) => { ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
write!(f, "ClosureKind({:?}, {:?})", closure_def_id, kind) write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
} }
ty::Predicate::ConstEvaluatable(def_id, substs) => { ty::Predicate::ConstEvaluatable(def_id, substs) => {
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)