From ce340af738909feae304f6617bcef55bbb8b7101 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 Oct 2016 12:39:42 -0400 Subject: [PATCH] move outlives_components onto tcx --- src/librustc/ty/outlives.rs | 22 ++++++++-------------- src/librustc/ty/wf.rs | 3 ++- src/librustc_typeck/check/regionck.rs | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index a4edd3b93c94..51feab9d40c9 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -12,8 +12,7 @@ // refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that // RFC for reference. -use infer::InferCtxt; -use ty::{self, Ty, TypeFoldable}; +use ty::{self, Ty, TyCtxt, TypeFoldable}; #[derive(Debug)] pub enum Component<'tcx> { @@ -55,9 +54,9 @@ pub enum Component<'tcx> { EscapingProjection(Vec>), } -impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { +impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Returns all the things that must outlive `'a` for the condition - /// `ty0: 'a` to hold. + /// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**. pub fn outlives_components(&self, ty0: Ty<'tcx>) -> Vec> { let mut components = vec![]; @@ -148,16 +147,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } - // If we encounter an inference variable, try to resolve it - // and proceed with resolved version. If we cannot resolve it, - // then record the unresolved variable as a component. - ty::TyInfer(_) => { - let ty = self.resolve_type_vars_if_possible(&ty); - if let ty::TyInfer(infer_ty) = ty.sty { - out.push(Component::UnresolvedInferenceVariable(infer_ty)); - } else { - self.compute_components(ty, out); - } + // We assume that inference variables are fully resolved. + // So, if we encounter an inference variable, just record + // the unresolved variable as a component. + ty::TyInfer(infer_ty) => { + out.push(Component::UnresolvedInferenceVariable(infer_ty)); } // Most types do not introduce any region binders, nor diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 1135199d2254..1392855fdb66 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -178,7 +178,8 @@ pub fn implied_bounds<'a, 'gcx, 'tcx>( match infcx.tcx.no_late_bound_regions(data) { None => vec![], Some(ty::OutlivesPredicate(ty_a, r_b)) => { - let components = infcx.outlives_components(ty_a); + let ty_a = infcx.resolve_type_vars_if_possible(&ty_a); + let components = infcx.tcx.outlives_components(ty_a); implied_bounds_from_components(r_b, components) } }, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 939deee27c60..23201acf8eeb 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1474,7 +1474,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { assert!(!ty.has_escaping_regions()); - let components = self.outlives_components(ty); + let components = self.tcx.outlives_components(ty); self.components_must_outlive(origin, components, region); }