diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index 33e5f6cd3e2..f60ae20827a 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -32,15 +32,15 @@ //! [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin}; +use rustc_data_structures::indexed_vec::IndexVec; +use rustc_data_structures::sync::Lrc; use serialize::UseSpecializedDecodable; use std::fmt::Debug; use std::ops::Index; use syntax::codemap::Span; -use ty::{self, CanonicalVar, Lift, Region, Slice, TyCtxt}; -use ty::subst::Kind; use ty::fold::TypeFoldable; - -use rustc_data_structures::indexed_vec::IndexVec; +use ty::subst::Kind; +use ty::{self, CanonicalVar, Lift, Region, Slice, TyCtxt}; mod canonicalizer; @@ -59,7 +59,7 @@ pub struct Canonical<'gcx, V> { pub type CanonicalVarInfos<'gcx> = &'gcx Slice; -impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> { } +impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> {} /// A set of values corresponding to the canonical variables from some /// `Canonical`. You can give these values to @@ -124,6 +124,9 @@ pub struct QueryResult<'tcx, R> { pub value: R, } +pub type CanonicalizedQueryResult<'gcx, T> = + Lrc>::Lifted>>>; + /// Indicates whether or not we were able to prove the query to be /// true. #[derive(Copy, Clone, Debug)] @@ -246,9 +249,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { CanonicalVarKind::Ty(ty_kind) => { let ty = match ty_kind { CanonicalTyVarKind::General => { - self.next_ty_var( - TypeVariableOrigin::MiscVariable(span), - ) + self.next_ty_var(TypeVariableOrigin::MiscVariable(span)) } CanonicalTyVarKind::Int => self.tcx.mk_int_var(self.next_int_var_id()), @@ -258,9 +259,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { ty.into() } - CanonicalVarKind::Region => { - self.next_region_var(RegionVariableOrigin::MiscVariable(span)).into() - } + CanonicalVarKind::Region => self + .next_region_var(RegionVariableOrigin::MiscVariable(span)) + .into(), } } } @@ -343,3 +344,19 @@ impl<'tcx> Index for CanonicalVarValues<'tcx> { &self.var_values[value] } } + +impl<'gcx: 'tcx, 'tcx, T> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, T> +where + T: TypeFoldable<'tcx> + Lift<'gcx>, + T::Lifted: Debug, +{ + // we ought to intern this, but I'm too lazy just now + type Canonicalized = Lrc>>; + + fn intern( + _gcx: TyCtxt<'_, 'gcx, 'gcx>, + value: Canonical<'gcx, Self::Lifted>, + ) -> Self::Canonicalized { + Lrc::new(value) + } +} diff --git a/src/librustc/infer/canonical/query_result.rs b/src/librustc/infer/canonical/query_result.rs index 4d03ccb42a9..ab8fb519afd 100644 --- a/src/librustc/infer/canonical/query_result.rs +++ b/src/librustc/infer/canonical/query_result.rs @@ -19,11 +19,13 @@ use infer::canonical::substitute::substitute_value; use infer::canonical::{ - Canonical, CanonicalVarValues, Canonicalize, Certainty, QueryRegionConstraint, QueryResult, + Canonical, CanonicalVarValues, Canonicalize, CanonicalizedQueryResult, Certainty, + QueryRegionConstraint, QueryResult, }; use infer::region_constraints::{Constraint, RegionConstraintData}; use infer::{InferCtxt, InferOk, InferResult, RegionObligation}; use rustc_data_structures::indexed_vec::Idx; +use rustc_data_structures::indexed_vec::IndexVec; use std::fmt::Debug; use syntax::ast; use traits::query::NoSolution; @@ -31,12 +33,7 @@ use traits::{FulfillmentContext, TraitEngine}; use traits::{Obligation, ObligationCause, PredicateObligation}; use ty::fold::TypeFoldable; use ty::subst::{Kind, UnpackedKind}; -use ty::{self, CanonicalVar, TyCtxt}; - -use rustc_data_structures::indexed_vec::IndexVec; - -type CanonicalizedQueryResult<'gcx, 'tcx, T> = - as Canonicalize<'gcx, 'tcx>>::Canonicalized; +use ty::{self, CanonicalVar, Lift, TyCtxt}; impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// This method is meant to be invoked as the final step of a canonical query @@ -63,10 +60,10 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { inference_vars: CanonicalVarValues<'tcx>, answer: T, fulfill_cx: &mut FulfillmentContext<'tcx>, - ) -> Result, NoSolution> + ) -> Result, NoSolution> where - T: Debug, - QueryResult<'tcx, T>: Canonicalize<'gcx, 'tcx>, + T: Debug + Lift<'gcx> + TypeFoldable<'tcx>, + T::Lifted: Debug, { let query_result = self.make_query_result(inference_vars, answer, fulfill_cx)?; let (canonical_result, _) = self.canonicalize_response(&query_result); diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 96bed122350..671809c059a 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -9,13 +9,12 @@ // except according to those terms. use infer::at::At; -use infer::canonical::{Canonical, Canonicalize, QueryResult}; +use infer::canonical::{Canonical, Canonicalize}; use infer::InferOk; use std::iter::FromIterator; use traits::query::CanonicalTyGoal; use ty::{self, Ty, TyCtxt}; use ty::subst::Kind; -use rustc_data_structures::sync::Lrc; impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> { /// Given a type `ty` of some value being dropped, computes a set @@ -181,18 +180,6 @@ impl_stable_hash_for!(struct DropckOutlivesResult<'tcx> { kinds, overflows }); -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, DropckOutlivesResult<'tcx>> { - // we ought to intern this, but I'm too lazy just now - type Canonicalized = Lrc>>>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - Lrc::new(value) - } -} - impl_stable_hash_for!(struct DtorckConstraint<'tcx> { outlives, dtorck_types, diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index d0ae0bdac8c..22b47458bce 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -14,10 +14,9 @@ use infer::{InferCtxt, InferOk}; use infer::at::At; -use infer::canonical::{Canonical, Canonicalize, QueryResult}; +use infer::canonical::{Canonical, Canonicalize}; use middle::const_val::ConstVal; use mir::interpret::GlobalId; -use rustc_data_structures::sync::Lrc; use traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; use traits::query::CanonicalProjectionGoal; use traits::project::Normalized; @@ -262,18 +261,6 @@ impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, ty::Pr } } -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, NormalizationResult<'tcx>> { - // we ought to intern this, but I'm too lazy just now - type Canonicalized = Lrc>>>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - Lrc::new(value) - } -} - impl_stable_hash_for!(struct NormalizationResult<'tcx> { normalized_ty });