diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 9ff8944efe4ff..07f94dc773f40 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -206,29 +206,29 @@ impl<'a, 'gcx, 'tcx> HashStable> for ty::Pr hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::Predicate::Trait(ref pred) => { + match self.kind { + ty::PredicateKind::Trait(ref pred) => { pred.hash_stable(hcx, hasher); } - ty::Predicate::Subtype(ref pred) => { + ty::PredicateKind::Subtype(ref pred) => { pred.hash_stable(hcx, hasher); } - ty::Predicate::RegionOutlives(ref pred) => { + ty::PredicateKind::RegionOutlives(ref pred) => { pred.hash_stable(hcx, hasher); } - ty::Predicate::TypeOutlives(ref pred) => { + ty::PredicateKind::TypeOutlives(ref pred) => { pred.hash_stable(hcx, hasher); } - ty::Predicate::Projection(ref pred) => { + ty::PredicateKind::Projection(ref pred) => { pred.hash_stable(hcx, hasher); } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { ty.hash_stable(hcx, hasher); } - ty::Predicate::ObjectSafe(def_id) => { + ty::PredicateKind::ObjectSafe(def_id) => { def_id.hash_stable(hcx, hasher); } - ty::Predicate::ClosureKind(def_id, closure_kind) => { + ty::PredicateKind::ClosureKind(def_id, closure_kind) => { def_id.hash_stable(hcx, hasher); closure_kind.hash_stable(hcx, hasher); } diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index 412ca286188c3..1ae4dde1da941 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -45,7 +45,7 @@ use ty::{self, Ty, TyCtxt}; use ty::error::TypeError; use ty::relate::{self, Relate, RelateResult, TypeRelation}; use ty::subst::Substs; -use traits::{Obligation, PredicateObligations}; +use traits::{PredicateObligations}; use syntax::ast; use syntax_pos::Span; @@ -204,6 +204,7 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> { -> RelateResult<'tcx, ()> { use self::RelationDir::*; + let tcx = self.tcx(); // Get the actual variable that b_vid has been inferred to debug_assert!(self.infcx.type_variables.borrow_mut().probe(b_vid).is_unknown()); @@ -227,9 +228,9 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> { self.infcx.type_variables.borrow_mut().instantiate(b_vid, b_ty); if needs_wf { - self.obligations.push(Obligation::new(self.trace.cause.clone(), - param_env, - ty::Predicate::WellFormed(b_ty))); + self.obligations.push(tcx.predicate_obligation(self.trace.cause.clone(), + param_env, + ty::PredicateKind::WellFormed(b_ty))); } // Finally, relate `b_ty` to `a_ty`, as described in previous comment. diff --git a/src/librustc/infer/sub.rs b/src/librustc/infer/sub.rs index 2ac386ffec68f..3ab88aee60683 100644 --- a/src/librustc/infer/sub.rs +++ b/src/librustc/infer/sub.rs @@ -11,7 +11,6 @@ use super::SubregionOrigin; use super::combine::{CombineFields, RelationDir}; -use traits::Obligation; use ty::{self, Ty, TyCtxt}; use ty::TyVar; use ty::fold::TypeFoldable; @@ -80,6 +79,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> if a == b { return Ok(a); } let infcx = self.fields.infcx; + let tcx = infcx.tcx; let a = infcx.type_variables.borrow_mut().replace_if_possible(a); let b = infcx.type_variables.borrow_mut().replace_if_possible(b); match (&a.sty, &b.sty) { @@ -97,10 +97,10 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> // is important to the occurs check later on. infcx.type_variables.borrow_mut().sub(a_vid, b_vid); self.fields.obligations.push( - Obligation::new( + tcx.predicate_obligation( self.fields.trace.cause.clone(), self.param_env, - ty::Predicate::Subtype( + ty::PredicateKind::Subtype( ty::Binder(ty::SubtypePredicate { a_is_expected: self.a_is_expected, a, diff --git a/src/librustc/middle/free_region.rs b/src/librustc/middle/free_region.rs index d44248baf466f..b0ba90454ca49 100644 --- a/src/librustc/middle/free_region.rs +++ b/src/librustc/middle/free_region.rs @@ -139,17 +139,17 @@ impl<'tcx> FreeRegionMap<'tcx> { predicates: &[ty::Predicate<'tcx>]) { debug!("relate_free_regions_from_predicates(predicates={:?})", predicates); for predicate in predicates { - match *predicate { - ty::Predicate::Projection(..) | - ty::Predicate::Trait(..) | - ty::Predicate::Subtype(..) | - ty::Predicate::WellFormed(..) | - ty::Predicate::ObjectSafe(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::TypeOutlives(..) => { + match predicate.kind { + ty::PredicateKind::Projection(..) | + ty::PredicateKind::Trait(..) | + ty::PredicateKind::Subtype(..) | + ty::PredicateKind::WellFormed(..) | + ty::PredicateKind::ObjectSafe(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::TypeOutlives(..) => { // No region bounds here } - ty::Predicate::RegionOutlives(ty::Binder(ty::OutlivesPredicate(r_a, r_b))) => { + ty::PredicateKind::RegionOutlives(ty::Binder(ty::OutlivesPredicate(r_a, r_b))) => { self.relate_regions(r_b, r_a); } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 060f9ac272a8a..e42237f02a8cd 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -123,8 +123,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return true } - let (cond, error) = match (cond, error) { - (&ty::Predicate::Trait(..), &ty::Predicate::Trait(error)) + let (cond, error) = match (&cond.kind, &error.kind) { + (&ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(error)) => (cond, error), _ => { // FIXME: make this work in other cases too. @@ -133,7 +133,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }; for implication in super::elaborate_predicates(self.tcx, vec![cond.clone()]) { - if let ty::Predicate::Trait(implication) = implication { + if let ty::PredicateKind::Trait(implication) = implication.kind { // FIXME: I'm just not taking associated types at all here. // Eventually I'll need to implement param-env-aware // `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic. @@ -191,7 +191,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, '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::Predicate::Projection(ref data) = predicate { + if let ty::PredicateKind::Projection(ref data) = predicate.kind { let mut selcx = SelectionContext::new(self); let (data, _) = self.replace_late_bound_regions_with_fresh_var( obligation.cause.span, @@ -546,8 +546,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { .emit(); return; } - match obligation.predicate { - ty::Predicate::Trait(ref trait_ref) => { + match obligation.predicate.kind { + ty::PredicateKind::Trait(ref trait_ref) => { let trait_ref = self.resolve_type_vars_if_possible(trait_ref); if self.tcx.sess.has_errors() && trait_ref.references_error() { @@ -569,7 +569,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "{}", message.unwrap_or_else(|| { format!("the trait bound `{}` is not satisfied{}", - trait_ref.to_predicate(), post_message) + trait_ref.to_predicate(self.tcx), post_message) })); if let Some(ref s) = label { @@ -599,7 +599,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // "the type `T` can't be frobnicated" // which is somewhat confusing. err.help(&format!("consider adding a `where {}` bound", - trait_ref.to_predicate())); + trait_ref.to_predicate(self.tcx))); } else if !have_alt_message { // Can't show anything else useful, try to find similar impls. let impl_candidates = self.find_similar_impl_candidates(trait_ref); @@ -609,14 +609,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } - ty::Predicate::Subtype(ref predicate) => { + ty::PredicateKind::Subtype(ref predicate) => { // Errors for Subtype predicates show up as // `FulfillmentErrorCode::CodeSubtypeError`, // not selection error. span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate) } - ty::Predicate::RegionOutlives(ref predicate) => { + ty::PredicateKind::RegionOutlives(ref predicate) => { let predicate = self.resolve_type_vars_if_possible(predicate); let err = self.region_outlives_predicate(&obligation.cause, obligation.param_env, @@ -626,7 +626,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { predicate, err) } - ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => { + ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => { let predicate = self.resolve_type_vars_if_possible(&obligation.predicate); struct_span_err!(self.tcx.sess, span, E0280, @@ -634,14 +634,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { predicate) } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { let violations = self.tcx.object_safety_violations(trait_def_id); self.tcx.report_object_safety_error(span, trait_def_id, violations) } - ty::Predicate::ClosureKind(closure_def_id, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, kind) => { let found_kind = self.closure_kind(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(); @@ -680,7 +680,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { // WF predicates cannot themselves make // errors. They can only block due to // ambiguity; otherwise, they always @@ -876,8 +876,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - match predicate { - ty::Predicate::Trait(trait_ref) => { + match predicate.kind { + ty::PredicateKind::Trait(trait_ref) => { let self_ty = trait_ref.self_ty(); if predicate.references_error() { return; @@ -924,7 +924,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { // Same hacky approach as above to avoid deluging user // with error messages. if !ty.references_error() && !self.tcx.sess.has_errors() { @@ -932,7 +932,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::Subtype(ref data) => { if data.references_error() || self.tcx.sess.has_errors() { // no need to overload user in such cases } else { @@ -1007,11 +1007,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { &cleaned_pred ).value; - let obligation = Obligation::new( - ObligationCause::dummy(), - param_env, - cleaned_pred.to_predicate() - ); + let obligation = self.tcx.predicate_obligation(ObligationCause::dummy(), + param_env, + cleaned_pred); selcx.evaluate_obligation(&obligation) }) @@ -1118,7 +1116,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref); err.note(&format!("required because it appears within the type `{}`", parent_trait_ref.self_ty())); - let parent_predicate = parent_trait_ref.to_predicate(); + let parent_predicate = parent_trait_ref.to_predicate(self.tcx); self.note_obligation_cause_code(err, &parent_predicate, &data.parent_code); @@ -1129,7 +1127,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { &format!("required because of the requirements on the impl of `{}` for `{}`", parent_trait_ref, parent_trait_ref.self_ty())); - let parent_predicate = parent_trait_ref.to_predicate(); + let parent_predicate = parent_trait_ref.to_predicate(self.tcx); self.note_obligation_cause_code(err, &parent_predicate, &data.parent_code); diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 803fa43f2d7d4..6f67005e9be23 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -153,7 +153,7 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> { cause, recursion_depth: 0, param_env, - predicate: trait_ref.to_predicate() + predicate: trait_ref.to_predicate(infcx.tcx) }); } @@ -356,8 +356,8 @@ fn process_predicate<'a, 'gcx, 'tcx>( obligation.predicate = selcx.infcx().resolve_type_vars_if_possible(&obligation.predicate); } - match obligation.predicate { - ty::Predicate::Trait(trait_ref) => { + match obligation.predicate.kind { + ty::PredicateKind::Trait(trait_ref) => { let trait_obligation = obligation.with(trait_ref.clone()); if trait_ref.is_global() { @@ -414,7 +414,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::RegionOutlives(ref binder) => { + ty::PredicateKind::RegionOutlives(ref binder) => { match selcx.infcx().region_outlives_predicate(&obligation.cause, obligation.param_env, binder) { @@ -423,7 +423,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::TypeOutlives(ref binder) => { + ty::PredicateKind::TypeOutlives(ref binder) => { // Check if there are higher-ranked regions. match selcx.tcx().no_late_bound_regions(binder) { // If there are, inspect the underlying type further. @@ -459,7 +459,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(data.clone()); match project::poly_project_and_unify_type(selcx, &project_obligation) { Ok(None) => { @@ -473,7 +473,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if !selcx.tcx().is_object_safe(trait_def_id) { Err(CodeSelectionError(Unimplemented)) } else { @@ -481,7 +481,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::ClosureKind(closure_def_id, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, kind) => { match selcx.infcx().closure_kind(closure_def_id) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -496,7 +496,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { match ty::wf::obligations(selcx.infcx(), obligation.param_env, obligation.cause.body_id, @@ -509,7 +509,7 @@ fn process_predicate<'a, 'gcx, 'tcx>( } } - ty::Predicate::Subtype(ref subtype) => { + ty::PredicateKind::Subtype(ref subtype) => { match selcx.infcx().subtype_predicate(&obligation.cause, obligation.param_env, subtype) { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 2409bebaf9873..609352e7cd094 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -427,7 +427,7 @@ pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx param_env, cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID), recursion_depth: 0, - predicate: trait_ref.to_predicate(), + predicate: trait_ref.to_predicate(infcx.tcx), }; let result = SelectionContext::new(infcx) diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 49aaed48cc47e..f6ab44440751e 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -157,18 +157,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .into_iter() .map(|predicate| predicate.subst_supertrait(self, &trait_ref)) .any(|predicate| { - match predicate { - ty::Predicate::Trait(ref data) => { + match predicate.kind { + ty::PredicateKind::Trait(ref data) => { // In the case of a trait predicate, we can skip the "self" type. data.skip_binder().input_types().skip(1).any(|t| t.has_self_ty()) } - ty::Predicate::Projection(..) | - ty::Predicate::WellFormed(..) | - ty::Predicate::ObjectSafe(..) | - ty::Predicate::TypeOutlives(..) | - ty::Predicate::RegionOutlives(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::Subtype(..) => { + ty::PredicateKind::Projection(..) | + ty::PredicateKind::WellFormed(..) | + ty::PredicateKind::ObjectSafe(..) | + ty::PredicateKind::TypeOutlives(..) | + ty::PredicateKind::RegionOutlives(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::Subtype(..) => { false } } @@ -190,18 +190,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let predicates = predicates.instantiate_identity(self).predicates; elaborate_predicates(self, predicates) .any(|predicate| { - match predicate { - ty::Predicate::Trait(ref trait_pred) if trait_pred.def_id() == sized_def_id => { + match predicate.kind { + ty::PredicateKind::Trait(ref trait_pred) if trait_pred.def_id() == sized_def_id => { trait_pred.0.self_ty().is_self() } - ty::Predicate::Projection(..) | - ty::Predicate::Trait(..) | - ty::Predicate::Subtype(..) | - ty::Predicate::RegionOutlives(..) | - ty::Predicate::WellFormed(..) | - ty::Predicate::ObjectSafe(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::TypeOutlives(..) => { + ty::PredicateKind::Projection(..) | + ty::PredicateKind::Trait(..) | + ty::PredicateKind::Subtype(..) | + ty::PredicateKind::RegionOutlives(..) | + ty::PredicateKind::WellFormed(..) | + ty::PredicateKind::ObjectSafe(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::TypeOutlives(..) => { false } } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index a6c9decb3abe4..09109fea75726 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -365,7 +365,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>( ty: ty_var }); let obligation = Obligation::with_depth( - cause, depth + 1, param_env, projection.to_predicate()); + cause, depth + 1, param_env, projection.to_predicate(tcx)); Normalized { value: ty_var, obligations: vec![obligation] @@ -582,7 +582,7 @@ fn prune_cache_value_obligations<'a, 'gcx, 'tcx>(infcx: &'a InferCtxt<'a, 'gcx, let mut obligations: Vec<_> = result.obligations .iter() - .filter(|obligation| match obligation.predicate { + .filter(|obligation| match obligation.predicate.kind { // We found a `T: Foo` predicate, let's check // if `U` references any unresolved type // variables. In principle, we only care if this @@ -592,7 +592,7 @@ fn prune_cache_value_obligations<'a, 'gcx, 'tcx>(infcx: &'a InferCtxt<'a, 'gcx, // indirect obligations (e.g., we project to `?0`, // but we have `T: Foo` and `?1: Bar`). - ty::Predicate::Projection(ref data) => + ty::PredicateKind::Projection(ref data) => !infcx.any_unresolved_type_vars(&data.ty()), // We are only interested in `T: Foo` predicates, whre @@ -641,7 +641,7 @@ fn push_paranoid_cache_value_obligation<'a, 'gcx, 'tcx>(infcx: &'a InferCtxt<'a, let trait_obligation = Obligation { cause, recursion_depth: depth, param_env, - predicate: trait_ref.to_predicate() }; + predicate: trait_ref.to_predicate(infcx.tcx) }; result.obligations.push(trait_obligation); } @@ -672,11 +672,11 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc -> NormalizedTy<'tcx> { let trait_ref = projection_ty.trait_ref(selcx.tcx()).to_poly_trait_ref(); + let tcx = selcx.infcx().tcx; let trait_obligation = Obligation { cause, recursion_depth: depth, param_env, - predicate: trait_ref.to_predicate() }; - let tcx = selcx.infcx().tcx; + predicate: trait_ref.to_predicate(tcx) }; let def_id = projection_ty.item_def_id; let new_value = selcx.infcx().next_ty_var( param_env.universe, @@ -912,8 +912,8 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>( for predicate in env_predicates { debug!("assemble_candidates_from_predicates: predicate={:?}", predicate); - match predicate { - ty::Predicate::Projection(ref data) => { + match predicate.kind { + ty::PredicateKind::Projection(ref data) => { let same_def_id = data.0.projection_ty.item_def_id == obligation.predicate.item_def_id; @@ -1152,6 +1152,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>( obligation_trait_ref: ty::TraitRef<'tcx>) -> Progress<'tcx> { + let tcx = selcx.tcx(); let self_ty = obligation_trait_ref.self_ty(); let object_ty = selcx.infcx().shallow_resolve(self_ty); debug!("confirm_object_candidate(object_ty={:?})", @@ -1166,15 +1167,15 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>( } }; let env_predicates = data.projection_bounds().map(|p| { - p.with_self_ty(selcx.tcx(), object_ty).to_predicate() + p.with_self_ty(tcx, object_ty).to_predicate(tcx) }).collect(); let env_predicate = { - let env_predicates = elaborate_predicates(selcx.tcx(), env_predicates); + let env_predicates = elaborate_predicates(tcx, env_predicates); // select only those projections that are actually projecting an // item with the correct name - let env_predicates = env_predicates.filter_map(|p| match p { - ty::Predicate::Projection(data) => + let env_predicates = env_predicates.filter_map(|p| match p.kind { + ty::PredicateKind::Projection(data) => if data.0.projection_ty.item_def_id == obligation.predicate.item_def_id { Some(data) } else { @@ -1185,7 +1186,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>( // select those with a relevant trait-ref let mut env_predicates = env_predicates.filter(|data| { - let data_poly_trait_ref = data.to_poly_trait_ref(selcx.tcx()); + let data_poly_trait_ref = data.to_poly_trait_ref(tcx); selcx.infcx().probe(|_| { selcx.infcx().at(&obligation.cause, obligation.param_env) .instantiable_as(data_poly_trait_ref, obligation_trait_ref) @@ -1202,7 +1203,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>( debug!("confirm_object_candidate: no env-predicate \ found in object type `{:?}`; ill-formed", object_ty); - return Progress::error(selcx.tcx()); + return Progress::error(tcx); } } }; diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 23f2373e4e129..a797edf0196f2 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -35,7 +35,7 @@ use hir::def_id::DefId; use infer; use infer::{InferCtxt, InferOk, TypeFreshener}; use ty::subst::{Kind, Subst, Substs}; -use ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; +use ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable}; use ty::fast_reject; use ty::relate::TypeRelation; use middle::lang_items; @@ -614,14 +614,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { debug!("evaluate_predicate_recursively({:?})", obligation); - match obligation.predicate { - ty::Predicate::Trait(ref t) => { + match obligation.predicate.kind { + ty::PredicateKind::Trait(ref t) => { assert!(!t.has_escaping_regions()); let obligation = obligation.with(t.clone()); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } - ty::Predicate::Subtype(ref p) => { + ty::PredicateKind::Subtype(ref p) => { // does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { Some(Ok(InferOk { obligations, .. })) => { @@ -633,7 +633,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { } } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { match ty::wf::obligations(self.infcx, obligation.param_env, obligation.cause.body_id, @@ -645,13 +645,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { } } - ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => { // we do not consider region relationships when // evaluating trait matches EvaluatedToOk } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if self.tcx().is_object_safe(trait_def_id) { EvaluatedToOk } else { @@ -659,7 +659,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(data.clone()); match project::poly_project_and_unify_type(self, &project_obligation) { Ok(Some(subobligations)) => { @@ -681,7 +681,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { } } - ty::Predicate::ClosureKind(closure_def_id, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, kind) => { match self.infcx.closure_kind(closure_def_id) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -743,6 +743,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { stack: &TraitObligationStack<'o, 'tcx>) -> EvaluationResult { + let tcx = self.tcx(); + // In intercrate mode, whenever any of the types are unbound, // there can always be an impl. Even if there are no impls in // this crate, perhaps the type would be unified with @@ -828,9 +830,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { debug!("evaluate_stack({:?}) --> recursive", stack.fresh_trait_ref); let cycle = stack.iter().skip(1).take(rec_index+1); - let cycle = cycle.map(|stack| { - ty::Predicate::Trait(stack.obligation.predicate.to_poly_trait_ref()) - }); + let cycle = cycle.map(|stack| stack.obligation.predicate.to_predicate(tcx)); if self.coinductive_match(cycle) { debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref); @@ -864,8 +864,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { } fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { - let result = match predicate { - ty::Predicate::Trait(ref data) => { + let result = match predicate.kind { + ty::PredicateKind::Trait(ref data) => { self.tcx().trait_has_default_impl(data.def_id()) } _ => { @@ -2557,10 +2557,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation.predicate, trait_ref)?); - obligations.push(Obligation::new( + obligations.push(self.tcx().predicate_obligation( obligation.cause.clone(), obligation.param_env, - ty::Predicate::ClosureKind(closure_def_id, kind))); + ty::PredicateKind::ClosureKind(closure_def_id, kind))); Ok(VtableClosureData { closure_def_id, @@ -2650,7 +2650,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { nested.push(Obligation::with_depth(cause, obligation.recursion_depth + 1, obligation.param_env, - ty::Binder(outlives).to_predicate())); + ty::Binder(outlives).to_predicate(tcx))); } // T -> Trait. @@ -2688,12 +2688,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem), substs: tcx.mk_substs_trait(source, &[]), }; - push(tr.to_predicate()); + push(tr.to_predicate(tcx)); // If the type is `Foo+'a`, ensures that the type // being cast to `Foo+'a` outlives `'a`: let outlives = ty::OutlivesPredicate(source, r); - push(ty::Binder(outlives).to_predicate()); + push(ty::Binder(outlives).to_predicate(tcx)); } // [T; n] -> [T]. diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 3dc8f00434b81..cbb7fc4fde0bd 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -21,31 +21,31 @@ use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, fn anonymize_predicate<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, pred: &ty::Predicate<'tcx>) -> ty::Predicate<'tcx> { - match *pred { - ty::Predicate::Trait(ref data) => - ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data)), + tcx.mk_predicate(match pred.kind { + ty::PredicateKind::Trait(ref data) => + ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data)), - ty::Predicate::RegionOutlives(ref data) => - ty::Predicate::RegionOutlives(tcx.anonymize_late_bound_regions(data)), + ty::PredicateKind::RegionOutlives(ref data) => + ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data)), - ty::Predicate::TypeOutlives(ref data) => - ty::Predicate::TypeOutlives(tcx.anonymize_late_bound_regions(data)), + ty::PredicateKind::TypeOutlives(ref data) => + ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data)), - ty::Predicate::Projection(ref data) => - ty::Predicate::Projection(tcx.anonymize_late_bound_regions(data)), + ty::PredicateKind::Projection(ref data) => + ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)), - ty::Predicate::WellFormed(data) => - ty::Predicate::WellFormed(data), + ty::PredicateKind::WellFormed(data) => + ty::PredicateKind::WellFormed(data), - ty::Predicate::ObjectSafe(data) => - ty::Predicate::ObjectSafe(data), + ty::PredicateKind::ObjectSafe(data) => + ty::PredicateKind::ObjectSafe(data), - ty::Predicate::ClosureKind(closure_def_id, kind) => - ty::Predicate::ClosureKind(closure_def_id, kind), + ty::PredicateKind::ClosureKind(closure_def_id, kind) => + ty::PredicateKind::ClosureKind(closure_def_id, kind), - ty::Predicate::Subtype(ref data) => - ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data)), - } + ty::PredicateKind::Subtype(ref data) => + ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)), + }) } @@ -95,7 +95,7 @@ pub fn elaborate_trait_ref<'cx, 'gcx, 'tcx>( trait_ref: ty::PolyTraitRef<'tcx>) -> Elaborator<'cx, 'gcx, 'tcx> { - elaborate_predicates(tcx, vec![trait_ref.to_predicate()]) + elaborate_predicates(tcx, vec![trait_ref.to_predicate(tcx)]) } pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>( @@ -104,7 +104,7 @@ pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>( -> Elaborator<'cx, 'gcx, 'tcx> { let predicates = trait_refs.iter() - .map(|trait_ref| trait_ref.to_predicate()) + .map(|trait_ref| trait_ref.to_predicate(tcx)) .collect(); elaborate_predicates(tcx, predicates) } @@ -126,8 +126,8 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { fn push(&mut self, predicate: &ty::Predicate<'tcx>) { let tcx = self.visited.tcx; - match *predicate { - ty::Predicate::Trait(ref data) => { + match predicate.kind { + ty::PredicateKind::Trait(ref data) => { // Predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -149,30 +149,30 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { self.stack.extend(predicates); } - ty::Predicate::WellFormed(..) => { + ty::PredicateKind::WellFormed(..) => { // Currently, we do not elaborate WF predicates, // although we easily could. } - ty::Predicate::ObjectSafe(..) => { + ty::PredicateKind::ObjectSafe(..) => { // Currently, we do not elaborate object-safe // predicates. } - ty::Predicate::Subtype(..) => { + ty::PredicateKind::Subtype(..) => { // Currently, we do not "elaborate" predicates like `X // <: Y`, though conceivably we might. } - ty::Predicate::Projection(..) => { + ty::PredicateKind::Projection(..) => { // Nothing to elaborate in a projection predicate. } - ty::Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { // Nothing to elaborate when waiting for a closure's kind to be inferred. } - ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { // Nothing to elaborate from `'a: 'b`. } - ty::Predicate::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(ref data) => { // 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 @@ -201,13 +201,13 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { Component::Region(r) => if r.is_late_bound() { None } else { - Some(ty::Predicate::RegionOutlives( + Some(ty::PredicateKind::RegionOutlives( ty::Binder(ty::OutlivesPredicate(r, r_min)))) }, Component::Param(p) => { let ty = tcx.mk_param(p.idx, p.name); - Some(ty::Predicate::TypeOutlives( + Some(ty::PredicateKind::TypeOutlives( ty::Binder(ty::OutlivesPredicate(ty, r_min)))) }, @@ -223,6 +223,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { None }, }) + .map(|pk| tcx.mk_predicate(pk)) .filter(|p| visited.insert(p))); } } @@ -332,7 +333,7 @@ impl<'tcx,I:Iterator>> Iterator for FilterToTraits { None => { return None; } - Some(ty::Predicate::Trait(data)) => { + Some(ty::Predicate { kind: ty::PredicateKind::Trait(data) }) => { return Some(data); } Some(_) => { @@ -397,7 +398,8 @@ pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>, }).collect() } -pub fn predicate_for_trait_ref<'tcx>( +pub fn predicate_for_trait_ref<'a, 'gcx, 'tcx>( + tcx: TyCtxt<'a, 'gcx, 'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, trait_ref: ty::TraitRef<'tcx>, @@ -408,7 +410,7 @@ pub fn predicate_for_trait_ref<'tcx>( cause, param_env, recursion_depth, - predicate: trait_ref.to_predicate(), + predicate: trait_ref.to_predicate(tcx), } } @@ -426,7 +428,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { def_id: trait_def_id, substs: self.mk_substs_trait(param_ty, ty_params) }; - predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth) + predicate_for_trait_ref(self, cause, param_env, trait_ref, recursion_depth) } /// Cast a trait reference into a reference to one of its super diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 705e5400130ef..6400bb8e60ddf 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -30,7 +30,7 @@ use mir::transform::Passes; use ty::subst::{Kind, Substs}; use ty::ReprOptions; use traits; -use ty::{self, Ty, TypeAndMut}; +use ty::{self, ToPredicate, Ty, TypeAndMut}; use ty::{TyS, TypeVariants, Slice}; use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region}; use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate}; @@ -1934,6 +1934,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.mk_substs(iter::once(s).chain(t.into_iter().cloned()).map(Kind::from)) } + pub fn mk_predicate(self, kind: ty::PredicateKind<'tcx>) -> ty::Predicate<'tcx> { + ty::Predicate { kind } + } + + pub fn predicate_obligation(self, + cause: traits::ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, + predicate: O) + -> traits::PredicateObligation<'tcx> + where O: ToPredicate<'tcx> + { + let predicate = predicate.to_predicate(self); + traits::Obligation::new(cause, param_env, predicate) + } + pub fn lint_node>(self, lint: &'static Lint, id: NodeId, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 79fb62107cce9..9fe2602807bfc 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -818,7 +818,12 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> { } #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] -pub enum Predicate<'tcx> { +pub struct Predicate<'tcx> { + pub kind: PredicateKind<'tcx> +} + +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +pub enum PredicateKind<'tcx> { /// Corresponds to `where Foo : Bar`. `Foo` here would be /// the `Self` type of the trait reference and `A`, `B`, and `C` /// would be the type parameters. @@ -920,24 +925,24 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> { // this trick achieves that). let substs = &trait_ref.0.substs; - match *self { - Predicate::Trait(ty::Binder(ref data)) => - Predicate::Trait(ty::Binder(data.subst(tcx, substs))), - Predicate::Subtype(ty::Binder(ref data)) => - Predicate::Subtype(ty::Binder(data.subst(tcx, substs))), - Predicate::RegionOutlives(ty::Binder(ref data)) => - Predicate::RegionOutlives(ty::Binder(data.subst(tcx, substs))), - Predicate::TypeOutlives(ty::Binder(ref data)) => - Predicate::TypeOutlives(ty::Binder(data.subst(tcx, substs))), - Predicate::Projection(ty::Binder(ref data)) => - Predicate::Projection(ty::Binder(data.subst(tcx, substs))), - Predicate::WellFormed(data) => - Predicate::WellFormed(data.subst(tcx, substs)), - Predicate::ObjectSafe(trait_def_id) => - Predicate::ObjectSafe(trait_def_id), - Predicate::ClosureKind(closure_def_id, kind) => - Predicate::ClosureKind(closure_def_id, kind), - } + tcx.mk_predicate(match self.kind { + PredicateKind::Trait(ty::Binder(ref data)) => + PredicateKind::Trait(ty::Binder(data.subst(tcx, substs))), + PredicateKind::Subtype(ty::Binder(ref data)) => + PredicateKind::Subtype(ty::Binder(data.subst(tcx, substs))), + PredicateKind::RegionOutlives(ty::Binder(ref data)) => + PredicateKind::RegionOutlives(ty::Binder(data.subst(tcx, substs))), + PredicateKind::TypeOutlives(ty::Binder(ref data)) => + PredicateKind::TypeOutlives(ty::Binder(data.subst(tcx, substs))), + PredicateKind::Projection(ty::Binder(ref data)) => + PredicateKind::Projection(ty::Binder(data.subst(tcx, substs))), + PredicateKind::WellFormed(data) => + PredicateKind::WellFormed(data.subst(tcx, substs)), + PredicateKind::ObjectSafe(trait_def_id) => + PredicateKind::ObjectSafe(trait_def_id), + PredicateKind::ClosureKind(closure_def_id, kind) => + PredicateKind::ClosureKind(closure_def_id, kind), + }) } } @@ -1006,37 +1011,47 @@ impl<'tcx> ToPolyTraitRef<'tcx> for TraitRef<'tcx> { } } -pub trait ToPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx>; +pub trait ToPredicate<'tcx>: Sized { + fn to_predicate<'a, 'gcx>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Predicate<'tcx> { + tcx.mk_predicate(self.to_predicate_kind()) + } + + fn to_predicate_kind(self) -> PredicateKind<'tcx>; +} + +impl<'tcx> ToPredicate<'tcx> for PredicateKind<'tcx> { + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + self + } } impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(self.to_poly_trait_ref()) + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + ty::PredicateKind::Trait(self.to_poly_trait_ref()) } } impl<'tcx> ToPredicate<'tcx> for PolyTraitRef<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(*self) + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + ty::PredicateKind::Trait(self) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::RegionOutlives(self.clone()) + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + PredicateKind::RegionOutlives(self) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::TypeOutlives(self.clone()) + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + PredicateKind::TypeOutlives(self) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::Projection(self.clone()) + fn to_predicate_kind(self) -> PredicateKind<'tcx> { + PredicateKind::Projection(self) } } @@ -1045,29 +1060,29 @@ impl<'tcx> Predicate<'tcx> { /// cases this is skipping over a binder, so late-bound regions /// with depth 0 are bound by the predicate. pub fn walk_tys(&self) -> IntoIter> { - let vec: Vec<_> = match *self { - ty::Predicate::Trait(ref data) => { + let vec: Vec<_> = match self.kind { + ty::PredicateKind::Trait(ref data) => { data.skip_binder().input_types().collect() } - ty::Predicate::Subtype(ty::Binder(SubtypePredicate { a, b, a_is_expected: _ })) => { + ty::PredicateKind::Subtype(ty::Binder(SubtypePredicate { a, b, a_is_expected: _ })) => { vec![a, b] } - ty::Predicate::TypeOutlives(ty::Binder(ref data)) => { + ty::PredicateKind::TypeOutlives(ty::Binder(ref data)) => { vec![data.0] } - ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { vec![] } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { data.0.projection_ty.substs.types().chain(Some(data.0.ty)).collect() } - ty::Predicate::WellFormed(data) => { + ty::PredicateKind::WellFormed(data) => { vec![data] } - ty::Predicate::ObjectSafe(_trait_def_id) => { + ty::PredicateKind::ObjectSafe(_trait_def_id) => { vec![] } - ty::Predicate::ClosureKind(_closure_def_id, _kind) => { + ty::PredicateKind::ClosureKind(_closure_def_id, _kind) => { vec![] } }; @@ -1081,17 +1096,17 @@ impl<'tcx> Predicate<'tcx> { } pub fn to_opt_poly_trait_ref(&self) -> Option> { - match *self { - Predicate::Trait(t) => { + match self.kind { + PredicateKind::Trait(t) => { Some(t) } - Predicate::Projection(..) | - Predicate::Subtype(..) | - Predicate::RegionOutlives(..) | - Predicate::WellFormed(..) | - Predicate::ObjectSafe(..) | - Predicate::ClosureKind(..) | - Predicate::TypeOutlives(..) => { + PredicateKind::Projection(..) | + PredicateKind::Subtype(..) | + PredicateKind::RegionOutlives(..) | + PredicateKind::WellFormed(..) | + PredicateKind::ObjectSafe(..) | + PredicateKind::ClosureKind(..) | + PredicateKind::TypeOutlives(..) => { None } } @@ -1816,7 +1831,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { let sized_predicate = Binder(TraitRef { def_id: sized_trait, substs: tcx.mk_substs_trait(ty, &[]) - }).to_predicate(); + }).to_predicate(tcx); let predicates = tcx.predicates_of(self.did).predicates; if predicates.into_iter().any(|p| p == sized_predicate) { vec![] diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index d2d9cf3d51aff..14f665525f3c8 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ty::{self, Lift, Ty, TyCtxt}; +use ty::{self, Lift, ToPredicate, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use rustc_data_structures::accumulate_vec::AccumulateVec; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -184,32 +184,32 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { type Lifted = ty::Predicate<'tcx>; fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { - match *self { - ty::Predicate::Trait(ref binder) => { - tcx.lift(binder).map(ty::Predicate::Trait) + match self.kind { + ty::PredicateKind::Trait(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Trait) } - ty::Predicate::Subtype(ref binder) => { - tcx.lift(binder).map(ty::Predicate::Subtype) + ty::PredicateKind::Subtype(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Subtype) } - ty::Predicate::RegionOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::RegionOutlives) + ty::PredicateKind::RegionOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::RegionOutlives) } - ty::Predicate::TypeOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::TypeOutlives) + ty::PredicateKind::TypeOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::TypeOutlives) } - ty::Predicate::Projection(ref binder) => { - tcx.lift(binder).map(ty::Predicate::Projection) + ty::PredicateKind::Projection(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Projection) } - ty::Predicate::WellFormed(ty) => { - tcx.lift(&ty).map(ty::Predicate::WellFormed) + ty::PredicateKind::WellFormed(ty) => { + tcx.lift(&ty).map(ty::PredicateKind::WellFormed) } - ty::Predicate::ClosureKind(closure_def_id, kind) => { - Some(ty::Predicate::ClosureKind(closure_def_id, kind)) + ty::PredicateKind::ClosureKind(closure_def_id, kind) => { + Some(ty::PredicateKind::ClosureKind(closure_def_id, kind)) } - ty::Predicate::ObjectSafe(trait_def_id) => { - Some(ty::Predicate::ObjectSafe(trait_def_id)) + ty::PredicateKind::ObjectSafe(trait_def_id) => { + Some(ty::PredicateKind::ObjectSafe(trait_def_id)) } - } + }.map(|k| k.to_predicate(tcx)) } } @@ -865,36 +865,36 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { - match *self { - ty::Predicate::Trait(ref a) => - ty::Predicate::Trait(a.fold_with(folder)), - ty::Predicate::Subtype(ref binder) => - ty::Predicate::Subtype(binder.fold_with(folder)), - ty::Predicate::RegionOutlives(ref binder) => - ty::Predicate::RegionOutlives(binder.fold_with(folder)), - ty::Predicate::TypeOutlives(ref binder) => - ty::Predicate::TypeOutlives(binder.fold_with(folder)), - ty::Predicate::Projection(ref binder) => - ty::Predicate::Projection(binder.fold_with(folder)), - ty::Predicate::WellFormed(data) => - ty::Predicate::WellFormed(data.fold_with(folder)), - ty::Predicate::ClosureKind(closure_def_id, kind) => - ty::Predicate::ClosureKind(closure_def_id, kind), - ty::Predicate::ObjectSafe(trait_def_id) => - ty::Predicate::ObjectSafe(trait_def_id), - } + match self.kind { + ty::PredicateKind::Trait(ref a) => + ty::PredicateKind::Trait(a.fold_with(folder)), + ty::PredicateKind::Subtype(ref binder) => + ty::PredicateKind::Subtype(binder.fold_with(folder)), + ty::PredicateKind::RegionOutlives(ref binder) => + ty::PredicateKind::RegionOutlives(binder.fold_with(folder)), + ty::PredicateKind::TypeOutlives(ref binder) => + ty::PredicateKind::TypeOutlives(binder.fold_with(folder)), + ty::PredicateKind::Projection(ref binder) => + ty::PredicateKind::Projection(binder.fold_with(folder)), + ty::PredicateKind::WellFormed(data) => + ty::PredicateKind::WellFormed(data.fold_with(folder)), + ty::PredicateKind::ClosureKind(closure_def_id, kind) => + ty::PredicateKind::ClosureKind(closure_def_id, kind), + ty::PredicateKind::ObjectSafe(trait_def_id) => + ty::PredicateKind::ObjectSafe(trait_def_id), + }.to_predicate(folder.tcx()) } fn super_visit_with>(&self, visitor: &mut V) -> bool { - match *self { - ty::Predicate::Trait(ref a) => a.visit_with(visitor), - ty::Predicate::Subtype(ref binder) => binder.visit_with(visitor), - ty::Predicate::RegionOutlives(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::WellFormed(data) => data.visit_with(visitor), - ty::Predicate::ClosureKind(_closure_def_id, _kind) => false, - ty::Predicate::ObjectSafe(_trait_def_id) => false, + match self.kind { + ty::PredicateKind::Trait(ref a) => a.visit_with(visitor), + ty::PredicateKind::Subtype(ref binder) => binder.visit_with(visitor), + ty::PredicateKind::RegionOutlives(ref binder) => binder.visit_with(visitor), + ty::PredicateKind::TypeOutlives(ref binder) => binder.visit_with(visitor), + ty::PredicateKind::Projection(ref binder) => binder.visit_with(visitor), + ty::PredicateKind::WellFormed(data) => data.visit_with(visitor), + ty::PredicateKind::ClosureKind(_closure_def_id, _kind) => false, + ty::PredicateKind::ObjectSafe(_trait_def_id) => false, } } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 3ab60a05ecbaa..b8d1b62b3dfd4 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -343,15 +343,16 @@ impl<'a, 'gcx, 'tcx> Binder> { -> ty::Predicate<'tcx> { use ty::ToPredicate; match *self.skip_binder() { - ExistentialPredicate::Trait(tr) => Binder(tr).with_self_ty(tcx, self_ty).to_predicate(), + ExistentialPredicate::Trait(tr) => + Binder(tr).with_self_ty(tcx, self_ty).to_predicate(tcx), ExistentialPredicate::Projection(p) => - ty::Predicate::Projection(Binder(p.with_self_ty(tcx, self_ty))), + Binder(p.with_self_ty(tcx, self_ty)).to_predicate(tcx), ExistentialPredicate::AutoTrait(did) => { let trait_ref = Binder(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]), }); - trait_ref.to_predicate() + trait_ref.to_predicate(tcx) } } } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 6d6ae58972baa..9447539a4104c 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -381,17 +381,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { traits::elaborate_predicates(self, predicates) .filter_map(|predicate| { - match predicate { - ty::Predicate::Projection(..) | - ty::Predicate::Trait(..) | - ty::Predicate::Subtype(..) | - ty::Predicate::WellFormed(..) | - ty::Predicate::ObjectSafe(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::RegionOutlives(..) => { + match predicate.kind { + ty::PredicateKind::Projection(..) | + ty::PredicateKind::Trait(..) | + ty::PredicateKind::Subtype(..) | + ty::PredicateKind::WellFormed(..) | + ty::PredicateKind::ObjectSafe(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::RegionOutlives(..) => { None } - ty::Predicate::TypeOutlives(ty::Binder(ty::OutlivesPredicate(t, r))) => { + ty::PredicateKind::TypeOutlives(ty::Binder(ty::OutlivesPredicate(t, 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 diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 2e53714a56279..e29fdcab6c44a 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -72,28 +72,28 @@ pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![] }; // (*) ok to skip binders, because wf code is prepared for it - match *predicate { - ty::Predicate::Trait(ref t) => { + match predicate.kind { + ty::PredicateKind::Trait(ref t) => { wf.compute_trait_ref(&t.skip_binder(), Elaborate::None); // (*) } - ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { } - ty::Predicate::TypeOutlives(ref t) => { + ty::PredicateKind::TypeOutlives(ref t) => { wf.compute(t.skip_binder().0); } - ty::Predicate::Projection(ref t) => { + ty::PredicateKind::Projection(ref t) => { let t = t.skip_binder(); // (*) wf.compute_projection(t.projection_ty); wf.compute(t.ty); } - ty::Predicate::WellFormed(t) => { + ty::PredicateKind::WellFormed(t) => { wf.compute(t); } - ty::Predicate::ObjectSafe(_) => { + ty::PredicateKind::ObjectSafe(_) => { } - ty::Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { } - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::Subtype(ref data) => { wf.compute(data.skip_binder().a); // (*) wf.compute(data.skip_binder().b); // (*) } @@ -161,6 +161,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { /// Pushes the obligations required for `trait_ref` to be WF into /// `self.out`. fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elaborate) { + let tcx = self.infcx.tcx; let obligations = self.nominal_obligations(trait_ref.def_id, trait_ref.substs); let cause = self.cause(traits::MiscObligation); @@ -170,7 +171,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { let predicates = obligations.iter() .map(|obligation| obligation.predicate.clone()) .collect(); - let implied_obligations = traits::elaborate_predicates(self.infcx.tcx, predicates); + let implied_obligations = traits::elaborate_predicates(tcx, predicates); let implied_obligations = implied_obligations.map(|pred| { traits::Obligation::new(cause.clone(), param_env, pred) }); @@ -182,9 +183,9 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { self.out.extend( trait_ref.substs.types() .filter(|ty| !ty.has_escaping_regions()) - .map(|ty| traits::Obligation::new(cause.clone(), - param_env, - ty::Predicate::WellFormed(ty)))); + .map(|ty| tcx.predicate_obligation(cause.clone(), + param_env, + ty::PredicateKind::WellFormed(ty)))); } /// Pushes the obligations required for `trait_ref::Item` to be WF @@ -197,7 +198,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { self.compute_trait_ref(&trait_ref, Elaborate::None); if !data.has_escaping_regions() { - let predicate = trait_ref.to_predicate(); + let predicate = trait_ref.to_predicate(self.infcx.tcx); let cause = self.cause(traits::ProjectionWf(data)); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -210,7 +211,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem), substs: self.infcx.tcx.mk_substs_trait(subty, &[]), }; - self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate())); + self.out.push(self.infcx.tcx.predicate_obligation(cause, self.param_env, trait_ref)); } } @@ -221,6 +222,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { fn compute(&mut self, ty0: Ty<'tcx>) -> bool { let mut subtys = ty0.walk(); let param_env = self.param_env; + let tcx = self.infcx.tcx; while let Some(ty) = subtys.next() { match ty.sty { ty::TyBool | @@ -268,10 +270,10 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { if !r.has_escaping_regions() && !mt.ty.has_escaping_regions() { let cause = self.cause(traits::ReferenceOutlivesReferent(ty)); self.out.push( - traits::Obligation::new( + tcx.predicate_obligation( cause, param_env, - ty::Predicate::TypeOutlives( + ty::PredicateKind::TypeOutlives( ty::Binder( ty::OutlivesPredicate(mt.ty, r))))); } @@ -313,10 +315,10 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { let component_traits = data.auto_traits().chain(data.principal().map(|p| p.def_id())); self.out.extend( - component_traits.map(|did| traits::Obligation::new( + component_traits.map(|did| tcx.predicate_obligation( cause.clone(), param_env, - ty::Predicate::ObjectSafe(did) + ty::PredicateKind::ObjectSafe(did) )) ); } @@ -343,9 +345,10 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { let cause = self.cause(traits::MiscObligation); self.out.push( // ...not the type we started from, so we made progress. - traits::Obligation::new(cause, - self.param_env, - ty::Predicate::WellFormed(ty))); + tcx.predicate_obligation( + cause, + self.param_env, + ty::PredicateKind::WellFormed(ty))); } else { // Yes, resolved, proceed with the // result. Should never return false because @@ -378,7 +381,8 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { .collect() } - fn from_object_ty(&mut self, ty: Ty<'tcx>, + fn from_object_ty(&mut self, + ty: Ty<'tcx>, data: ty::Binder<&'tcx ty::Slice>>, region: ty::Region<'tcx>) { // Imagine a type like this: @@ -414,17 +418,15 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { // am looking forward to the future here. if !data.has_escaping_regions() { - let implicit_bounds = - object_region_bounds(self.infcx.tcx, data); + let tcx = self.infcx.tcx; + let implicit_bounds = object_region_bounds(tcx, data); let explicit_bound = region; for implicit_bound in implicit_bounds { let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound)); let outlives = ty::Binder(ty::OutlivesPredicate(explicit_bound, implicit_bound)); - self.out.push(traits::Obligation::new(cause, - self.param_env, - outlives.to_predicate())); + self.out.push(tcx.predicate_obligation(cause, self.param_env, outlives)); } } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 7610323cca9cb..f70e4ee3c34c4 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -414,17 +414,17 @@ impl<'tcx> fmt::Debug for ty::adjustment::Adjustment<'tcx> { impl<'tcx> fmt::Debug for ty::Predicate<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ty::Predicate::Trait(ref a) => write!(f, "{:?}", a), - ty::Predicate::Subtype(ref pair) => write!(f, "{:?}", pair), - ty::Predicate::RegionOutlives(ref pair) => write!(f, "{:?}", pair), - ty::Predicate::TypeOutlives(ref pair) => write!(f, "{:?}", pair), - ty::Predicate::Projection(ref pair) => write!(f, "{:?}", pair), - ty::Predicate::WellFormed(ty) => write!(f, "WF({:?})", ty), - ty::Predicate::ObjectSafe(trait_def_id) => { + match self.kind { + ty::PredicateKind::Trait(ref a) => write!(f, "{:?}", a), + ty::PredicateKind::Subtype(ref pair) => write!(f, "{:?}", pair), + ty::PredicateKind::RegionOutlives(ref pair) => write!(f, "{:?}", pair), + ty::PredicateKind::TypeOutlives(ref pair) => write!(f, "{:?}", pair), + ty::PredicateKind::Projection(ref pair) => write!(f, "{:?}", pair), + ty::PredicateKind::WellFormed(ty) => write!(f, "WF({:?})", ty), + ty::PredicateKind::ObjectSafe(trait_def_id) => { write!(f, "ObjectSafe({:?})", trait_def_id) } - ty::Predicate::ClosureKind(closure_def_id, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, kind) => { write!(f, "ClosureKind({:?}, {:?})", closure_def_id, kind) } } @@ -1035,19 +1035,19 @@ impl fmt::Display for ty::ClosureKind { impl<'tcx> fmt::Display for ty::Predicate<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ty::Predicate::Trait(ref data) => + match self.kind { + ty::PredicateKind::Trait(ref data) => write!(f, "{}", data.map_bound_ref(|t| t.display_all_with_colon())), - ty::Predicate::Subtype(ref predicate) => write!(f, "{}", predicate), - ty::Predicate::RegionOutlives(ref predicate) => write!(f, "{}", predicate), - ty::Predicate::TypeOutlives(ref predicate) => write!(f, "{}", predicate), - ty::Predicate::Projection(ref predicate) => write!(f, "{}", predicate), - ty::Predicate::WellFormed(ty) => write!(f, "{} well-formed", ty), - ty::Predicate::ObjectSafe(trait_def_id) => + ty::PredicateKind::Subtype(ref predicate) => write!(f, "{}", predicate), + ty::PredicateKind::RegionOutlives(ref predicate) => write!(f, "{}", predicate), + ty::PredicateKind::TypeOutlives(ref predicate) => write!(f, "{}", predicate), + ty::PredicateKind::Projection(ref predicate) => write!(f, "{}", predicate), + ty::PredicateKind::WellFormed(ty) => write!(f, "{} well-formed", ty), + ty::PredicateKind::ObjectSafe(trait_def_id) => ty::tls::with(|tcx| { write!(f, "the trait `{}` is object-safe", tcx.item_path_str(trait_def_id)) }), - ty::Predicate::ClosureKind(closure_def_id, kind) => + ty::PredicateKind::ClosureKind(closure_def_id, kind) => ty::tls::with(|tcx| { write!(f, "the closure `{}` implements the trait `{}`", tcx.item_path_str(closure_def_id), kind) diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 73f1ae253cd29..d60103478cd86 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -21,7 +21,7 @@ use rustc::hir::def::{self, Def, CtorKind}; use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::middle::lang_items; use rustc::session::Session; -use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::{self, ToPredicate, Ty, TyCtxt}; use rustc::ty::subst::Substs; use rustc::mir::Mir; @@ -327,18 +327,16 @@ impl<'a, 'tcx> SpecializedDecoder> for DecodeContext Ok(ty::GenericPredicates { parent: Decodable::decode(self)?, predicates: (0..self.read_usize()?).map(|_| { - // Handle shorthands first, if we have an usize > 0x80. - if self.opaque.data[self.opaque.position()] & 0x80 != 0 { - let pos = self.read_usize()?; - assert!(pos >= SHORTHAND_OFFSET); - let pos = pos - SHORTHAND_OFFSET; - - self.with_position(pos, ty::Predicate::decode) - } else { - ty::Predicate::decode(self) - } - }) - .collect::, _>>()?, + // Handle shorthands first, if we have an usize > 0x80. + Ok(if self.opaque.data[self.opaque.position()] & 0x80 != 0 { + let pos = self.read_usize()?; + assert!(pos >= SHORTHAND_OFFSET); + let pos = pos - SHORTHAND_OFFSET; + self.with_position(pos, ty::PredicateKind::decode)? + } else { + ty::PredicateKind::decode(self)? + }.to_predicate(self.tcx())) + }).collect::>, Self::Error>>()?, }) } } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 98672880c76e9..df86404922b0e 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -396,11 +396,11 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> { let predicates = self.ev.tcx.predicates_of(self.item_def_id); for predicate in &predicates.predicates { predicate.visit_with(self); - match predicate { - &ty::Predicate::Trait(poly_predicate) => { + match predicate.kind { + ty::PredicateKind::Trait(poly_predicate) => { self.check_trait_ref(*poly_predicate.skip_binder()); }, - &ty::Predicate::Projection(poly_predicate) => { + ty::PredicateKind::Projection(poly_predicate) => { let tcx = self.ev.tcx; self.check_trait_ref( poly_predicate.skip_binder().projection_ty.trait_ref(tcx) @@ -684,11 +684,11 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> { let predicates = self.tcx.predicates_of(self.current_item); for predicate in &predicates.predicates { predicate.visit_with(self); - match predicate { - &ty::Predicate::Trait(poly_predicate) => { + match predicate.kind { + ty::PredicateKind::Trait(poly_predicate) => { self.check_trait_ref(*poly_predicate.skip_binder()); }, - &ty::Predicate::Projection(poly_predicate) => { + ty::PredicateKind::Projection(poly_predicate) => { let tcx = self.tcx; self.check_trait_ref( poly_predicate.skip_binder().projection_ty.trait_ref(tcx) @@ -931,18 +931,18 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { } ty::TyAnon(def_id, ..) => { for predicate in &self.tcx.predicates_of(def_id).predicates { - let trait_ref = match *predicate { - ty::Predicate::Trait(ref poly_trait_predicate) => { + let trait_ref = match predicate.kind { + ty::PredicateKind::Trait(ref poly_trait_predicate) => { Some(*poly_trait_predicate.skip_binder()) } - ty::Predicate::Projection(ref poly_projection_predicate) => { + ty::PredicateKind::Projection(ref poly_projection_predicate) => { if poly_projection_predicate.skip_binder().ty.visit_with(self) { return true; } Some(poly_projection_predicate.skip_binder() .projection_ty.trait_ref(self.tcx)) } - ty::Predicate::TypeOutlives(..) => None, + ty::PredicateKind::TypeOutlives(..) => None, _ => bug!("unexpected predicate: {:?}", predicate), }; if let Some(trait_ref) = trait_ref { @@ -1344,11 +1344,11 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> { let predicates = self.tcx.predicates_of(self.item_def_id); for predicate in &predicates.predicates { predicate.visit_with(self); - match predicate { - &ty::Predicate::Trait(poly_predicate) => { + match predicate.kind { + ty::PredicateKind::Trait(poly_predicate) => { self.check_trait_ref(*poly_predicate.skip_binder()); }, - &ty::Predicate::Projection(poly_predicate) => { + ty::PredicateKind::Projection(poly_predicate) => { let tcx = self.tcx; self.check_trait_ref( poly_predicate.skip_binder().projection_ty.trait_ref(tcx) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a85f102323720..7e5f7799e1601 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1406,7 +1406,7 @@ impl<'a, 'gcx, 'tcx> Bounds<'tcx> { def_id: sized, substs: tcx.mk_substs_trait(param_ty, &[]) }; - vec.push(trait_ref.to_predicate()); + vec.push(trait_ref.to_predicate(tcx)); } } @@ -1414,15 +1414,15 @@ impl<'a, 'gcx, 'tcx> Bounds<'tcx> { // account for the binder being introduced below; no need to shift `param_ty` // because, at present at least, it can only refer to early-bound regions let region_bound = tcx.mk_region(ty::fold::shift_region(*region_bound, 1)); - vec.push(ty::Binder(ty::OutlivesPredicate(param_ty, region_bound)).to_predicate()); + vec.push(ty::Binder(ty::OutlivesPredicate(param_ty, region_bound)).to_predicate(tcx)); } for bound_trait_ref in &self.trait_bounds { - vec.push(bound_trait_ref.to_predicate()); + vec.push(bound_trait_ref.to_predicate(tcx)); } for projection in &self.projection_bounds { - vec.push(projection.to_predicate()); + vec.push(projection.to_predicate(tcx)); } vec diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index a25deb7685af5..090491791a405 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -16,7 +16,7 @@ use super::method::MethodCallee; use rustc::infer::InferOk; use rustc::traits; use rustc::ty::{self, Ty, TraitRef}; -use rustc::ty::{ToPredicate, TypeFoldable}; +use rustc::ty::{TypeFoldable}; use rustc::ty::{LvaluePreference, NoPreference}; use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref}; @@ -118,9 +118,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id); let mut selcx = traits::SelectionContext::new(self.fcx); - let obligation = traits::Obligation::new(cause.clone(), - self.fcx.param_env, - trait_ref.to_predicate()); + let obligation = tcx.predicate_obligation(cause.clone(), self.fcx.param_env, trait_ref); if !selcx.evaluate_obligation(&obligation) { debug!("overloaded_deref_ty: cannot match obligation"); return None; diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index fa7a3c5a3d226..c354639301fcc 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -136,7 +136,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let sig = object_type.projection_bounds() .filter_map(|pb| { let pb = pb.with_self_ty(self.tcx, self.tcx.types.err); - self.deduce_sig_from_projection(&pb) + self.deduce_sig_from_projection(pb) }) .next(); let kind = object_type.principal() @@ -163,10 +163,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!("deduce_expectations_from_obligations: obligation.predicate={:?}", obligation.predicate); - match obligation.predicate { + match obligation.predicate.kind { // Given a Projection predicate, we can potentially infer // the complete signature. - ty::Predicate::Projection(ref proj_predicate) => { + ty::PredicateKind::Projection(proj_predicate) => { let trait_ref = proj_predicate.to_poly_trait_ref(self.tcx); self.self_type_matches_expected_vid(trait_ref, expected_vid) .and_then(|_| self.deduce_sig_from_projection(proj_predicate)) @@ -184,14 +184,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .iter() .map(|obligation| &obligation.obligation) .filter_map(|obligation| { - let opt_trait_ref = match obligation.predicate { - ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.tcx)), - ty::Predicate::Trait(data) => Some(data), - ty::Predicate::Subtype(..) => None, - ty::Predicate::RegionOutlives(..) => None, - ty::Predicate::TypeOutlives(..) => None, - ty::Predicate::WellFormed(..) => None, - ty::Predicate::ObjectSafe(..) => None, + let opt_trait_ref = match obligation.predicate.kind { + ty::PredicateKind::Projection(ref data) => Some(data.to_poly_trait_ref(self.tcx)), + ty::PredicateKind::Trait(data) => Some(data), + ty::PredicateKind::Subtype(..) => None, + ty::PredicateKind::RegionOutlives(..) => None, + ty::PredicateKind::TypeOutlives(..) => None, + ty::PredicateKind::WellFormed(..) => None, + ty::PredicateKind::ObjectSafe(..) => None, // NB: This predicate is created by breaking down a // `ClosureType: FnFoo()` predicate, where @@ -201,7 +201,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // this closure yet; this is exactly why the other // code is looking for a self type of a unresolved // inference variable. - ty::Predicate::ClosureKind(..) => None, + ty::PredicateKind::ClosureKind(..) => None, }; opt_trait_ref.and_then(|tr| self.self_type_matches_expected_vid(tr, expected_vid)) .and_then(|tr| self.tcx.lang_items().fn_trait_kind(tr.def_id())) @@ -215,7 +215,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Given a projection like "::Result == Y", we can deduce /// everything we need to know about a closure. fn deduce_sig_from_projection(&self, - projection: &ty::PolyProjectionPredicate<'tcx>) + projection: ty::PolyProjectionPredicate<'tcx>) -> Option> { let tcx = self.tcx; diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 99a5e96f10405..83be2dd37b1be 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -531,8 +531,8 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { let traits = [coerce_unsized_did, unsize_did]; while let Some(obligation) = queue.pop_front() { debug!("coerce_unsized resolve step: {:?}", obligation); - let trait_ref = match obligation.predicate { - ty::Predicate::Trait(ref tr) if traits.contains(&tr.def_id()) => { + let trait_ref = match obligation.predicate.kind { + ty::PredicateKind::Trait(ref tr) if traits.contains(&tr.def_id()) => { if unsize_did == tr.def_id() { if let ty::TyTuple(..) = tr.0.input_types().nth(1).unwrap().sty { debug!("coerce_unsized: found unsized tuple coercion"); diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 9f9b29a831adf..a8913c4a22600 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -547,8 +547,8 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.clone()) .filter_map(|predicate| { - match predicate { - ty::Predicate::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => + match predicate.kind { + ty::PredicateKind::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => Some(trait_pred), _ => None, } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index b741a4a9fc21c..e7f9e6e424b40 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -262,7 +262,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { traits::Obligation::misc(span, self.body_id, self.param_env, - poly_trait_ref.to_predicate()); + poly_trait_ref.to_predicate(self.tcx)); // Now we want to know if this can be matched let mut selcx = traits::SelectionContext::new(self); @@ -329,9 +329,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!("lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}", method_ty, obligation); - obligations.push(traits::Obligation::new(cause, - self.param_env, - ty::Predicate::WellFormed(method_ty))); + obligations.push(tcx.predicate_obligation(cause, + self.param_env, + ty::PredicateKind::WellFormed(method_ty))); let callee = MethodCallee { def_id, diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 8a567d7a57ec2..88114570eedc9 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -18,7 +18,7 @@ use hir::def_id::DefId; use hir::def::Def; use rustc::ty::subst::{Subst, Substs}; use rustc::traits::{self, ObligationCause}; -use rustc::ty::{self, Ty, ToPredicate, TraitRef, TypeFoldable}; +use rustc::ty::{self, Ty, TraitRef, TypeFoldable}; use rustc::infer::type_variable::TypeVariableOrigin; use rustc::util::nodemap::FxHashSet; use rustc::infer::{self, InferOk}; @@ -574,8 +574,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { .caller_bounds .iter() .filter_map(|predicate| { - match *predicate { - ty::Predicate::Trait(trait_predicate) => { + match predicate.kind { + ty::PredicateKind::Trait(trait_predicate) => { match trait_predicate.skip_binder().self_ty().sty { ty::TyParam(ref p) if *p == param_ty => { Some(trait_predicate) @@ -583,13 +583,13 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { _ => None, } } - ty::Predicate::Subtype(..) | - ty::Predicate::Projection(..) | - ty::Predicate::RegionOutlives(..) | - ty::Predicate::WellFormed(..) | - ty::Predicate::ObjectSafe(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::TypeOutlives(..) => None, + ty::PredicateKind::Subtype(..) | + ty::PredicateKind::Projection(..) | + ty::PredicateKind::RegionOutlives(..) | + ty::PredicateKind::WellFormed(..) | + ty::PredicateKind::ObjectSafe(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::TypeOutlives(..) => None, } }) .collect(); @@ -1022,9 +1022,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } TraitCandidate(trait_ref) => { - let predicate = trait_ref.to_predicate(); let obligation = - traits::Obligation::new(cause.clone(), self.param_env, predicate); + self.tcx.predicate_obligation(cause.clone(), self.param_env, trait_ref); if !selcx.evaluate_obligation(&obligation) { if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) { // This candidate's primary obligation doesn't even @@ -1055,7 +1054,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { let o = self.resolve_type_vars_if_possible(&o); if !selcx.evaluate_obligation(&o) { result = ProbeResult::NoMatch; - if let &ty::Predicate::Trait(ref pred) = &o.predicate { + if let ty::PredicateKind::Trait(ref pred) = o.predicate.kind { possibly_unsatisfied_predicates.push(*pred.skip_binder()); } } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 4044c0561c9d6..29fee39610900 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -61,7 +61,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Obligation::misc(span, self.body_id, self.param_env, - poly_trait_ref.to_predicate()); + poly_trait_ref.to_predicate(tcx)); SelectionContext::new(self).evaluate_obligation(&obligation) }) }) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index cd76ddcc0daa8..7cc50a7dd022e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1615,8 +1615,8 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { ty::GenericPredicates { parent: None, predicates: self.param_env.caller_bounds.iter().filter(|predicate| { - match **predicate { - ty::Predicate::Trait(ref data) => { + match predicate.kind { + ty::PredicateKind::Trait(ref data) => { data.0.self_ty().is_param(index) } _ => false @@ -2032,9 +2032,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { // WF obligations never themselves fail, so no real need to give a detailed cause: let cause = traits::ObligationCause::new(span, self.body_id, code); - self.register_predicate(traits::Obligation::new(cause, - self.param_env, - ty::Predicate::WellFormed(ty))); + self.register_predicate(self.tcx().predicate_obligation( + cause, + self.param_env, + ty::PredicateKind::WellFormed(ty))); } /// Registers obligations that all types appearing in `substs` are well-formed. diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index ac440c63df606..579d80bd78845 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -505,20 +505,20 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { .into_iter() .flat_map(|obligation| { assert!(!obligation.has_escaping_regions()); - match obligation.predicate { - ty::Predicate::Trait(..) | - ty::Predicate::Subtype(..) | - ty::Predicate::Projection(..) | - ty::Predicate::ClosureKind(..) | - ty::Predicate::ObjectSafe(..) => + match obligation.predicate.kind { + ty::PredicateKind::Trait(..) | + ty::PredicateKind::Subtype(..) | + ty::PredicateKind::Projection(..) | + ty::PredicateKind::ClosureKind(..) | + ty::PredicateKind::ObjectSafe(..) => vec![], - ty::Predicate::WellFormed(subty) => { + ty::PredicateKind::WellFormed(subty) => { wf_types.push(subty); vec![] } - ty::Predicate::RegionOutlives(ref data) => + ty::PredicateKind::RegionOutlives(ref data) => match self.tcx.no_late_bound_regions(data) { None => vec![], @@ -526,7 +526,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { vec![ImpliedBound::RegionSubRegion(r_b, r_a)], }, - ty::Predicate::TypeOutlives(ref data) => + ty::PredicateKind::TypeOutlives(ref data) => match self.tcx.no_late_bound_regions(data) { None => vec![], Some(ty::OutlivesPredicate(ty_a, r_b)) => { @@ -1808,8 +1808,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { traits::elaborate_predicates(self.tcx, predicates) .filter_map(|predicate| { // we're only interesting in `T : 'a` style predicates: - let outlives = match predicate { - ty::Predicate::TypeOutlives(data) => data, + let outlives = match predicate.kind { + ty::PredicateKind::TypeOutlives(data) => data, _ => { return None; } }; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 9c19aef5992e6..236dcbd5f01a8 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -271,8 +271,8 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { // traits. let has_predicates = predicates.predicates.iter().any(|predicate| { - match predicate { - &ty::Predicate::Trait(ref poly_trait_ref) => { + match predicate.kind { + ty::PredicateKind::Trait(poly_trait_ref) => { let self_ty = poly_trait_ref.0.self_ty(); !(self_ty.is_self() && poly_trait_ref.def_id() == trait_def_id) }, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e4ca0f82ea1a0..618a40547b366 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -314,7 +314,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result.predicates.push(ty::TraitRef { def_id: item_def_id, substs: Substs::identity_for_item(tcx, item_def_id) - }.to_predicate()); + }.to_predicate(tcx)); } generics } @@ -1441,7 +1441,7 @@ fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Add in a predicate that `Self:Trait` (where `Trait` is the // current trait). This is needed for builtin bounds. - predicates.push(trait_ref.to_poly_trait_ref().to_predicate()); + predicates.push(trait_ref.to_poly_trait_ref().to_predicate(tcx)); } // Collect the region predicates that were declared inline as @@ -1459,7 +1459,7 @@ fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for bound in ¶m.bounds { let bound_region = AstConv::ast_region_to_region(&icx, bound, None); let outlives = ty::Binder(ty::OutlivesPredicate(region, bound_region)); - predicates.push(outlives.to_predicate()); + predicates.push(outlives.to_predicate(tcx)); } } @@ -1495,10 +1495,10 @@ fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty, &mut projections); - predicates.push(trait_ref.to_predicate()); + predicates.push(trait_ref.to_predicate(tcx)); for projection in &projections { - predicates.push(projection.to_predicate()); + predicates.push(projection.to_predicate(tcx)); } } @@ -1507,7 +1507,7 @@ fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, lifetime, None); let pred = ty::Binder(ty::OutlivesPredicate(ty, region)); - predicates.push(ty::Predicate::TypeOutlives(pred)) + predicates.push(ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx)) } } } @@ -1518,7 +1518,7 @@ fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for bound in ®ion_pred.bounds { let r2 = AstConv::ast_region_to_region(&icx, bound, None); let pred = ty::Binder(ty::OutlivesPredicate(r1, r2)); - predicates.push(ty::Predicate::RegionOutlives(pred)) + predicates.push(ty::PredicateKind::RegionOutlives(pred).to_predicate(tcx)) } } @@ -1638,6 +1638,7 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, bound: &hir::TyParamBound) -> Vec> { + let tcx = astconv.tcx(); match *bound { hir::TraitTyParamBound(ref tr, hir::TraitBoundModifier::None) => { let mut projections = Vec::new(); @@ -1645,14 +1646,14 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, param_ty, &mut projections); projections.into_iter() - .map(|p| p.to_predicate()) - .chain(Some(pred.to_predicate())) + .map(|p| p.to_predicate(tcx)) + .chain(Some(pred.to_predicate(tcx))) .collect() } hir::RegionTyParamBound(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder(ty::OutlivesPredicate(param_ty, region)); - vec![ty::Predicate::TypeOutlives(pred)] + vec![ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx)] } hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => { Vec::new() diff --git a/src/librustc_typeck/constrained_type_params.rs b/src/librustc_typeck/constrained_type_params.rs index 09c7487e63560..79fae8f1dd6bf 100644 --- a/src/librustc_typeck/constrained_type_params.rs +++ b/src/librustc_typeck/constrained_type_params.rs @@ -169,7 +169,7 @@ pub fn setup_constraining_predicates<'tcx>(tcx: ty::TyCtxt, changed = false; for j in i..predicates.len() { - if let ty::Predicate::Projection(ref poly_projection) = predicates[j] { + if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].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(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index afe0f729d47c9..d7e24449c73da 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -922,17 +922,15 @@ impl Clean for hir::WherePredicate { impl<'a> Clean for ty::Predicate<'a> { fn clean(&self, cx: &DocContext) -> WherePredicate { - use rustc::ty::Predicate; - - match *self { - Predicate::Trait(ref pred) => pred.clean(cx), - Predicate::Subtype(ref pred) => pred.clean(cx), - Predicate::RegionOutlives(ref pred) => pred.clean(cx), - Predicate::TypeOutlives(ref pred) => pred.clean(cx), - Predicate::Projection(ref pred) => pred.clean(cx), - Predicate::WellFormed(_) => panic!("not user writable"), - Predicate::ObjectSafe(_) => panic!("not user writable"), - Predicate::ClosureKind(..) => panic!("not user writable"), + match self.kind { + ty::PredicateKind::Trait(ref pred) => pred.clean(cx), + ty::PredicateKind::Subtype(ref pred) => pred.clean(cx), + ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::TypeOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::Projection(ref pred) => pred.clean(cx), + ty::PredicateKind::WellFormed(_) => panic!("not user writable"), + ty::PredicateKind::ObjectSafe(_) => panic!("not user writable"), + ty::PredicateKind::ClosureKind(..) => panic!("not user writable"), } } } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index dd36b28bb39ac..3723caa2603fd 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -150,7 +150,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId, } let predicates = cx.tcx.super_predicates_of(child).predicates; predicates.iter().filter_map(|pred| { - if let ty::Predicate::Trait(ref pred) = *pred { + if let ty::PredicateKind::Trait(ref pred) = pred.kind { if pred.0.trait_ref.self_ty().is_self() { Some(pred.def_id()) } else {