From 0da0457593c5c1cb09f6197782ca73617860e897 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 20 Feb 2019 12:47:19 +0000 Subject: [PATCH] Clean up some generic substs handling --- src/librustc/infer/opaque_types/mod.rs | 11 ++++++++--- src/librustc/infer/outlives/obligations.rs | 20 +++++++++++++------- src/librustc_typeck/check/regionck.rs | 22 ++++++++++++++-------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 159bc1ceae2..1b7ecc7c3a6 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -381,10 +381,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { substs, item_def_id: _, }) => { - for r in substs.regions() { - bound_region(r); + for k in substs { + match k.unpack() { + UnpackedKind::Lifetime(lt) => bound_region(lt), + UnpackedKind::Type(ty) => types.push(ty), + UnpackedKind::Const(_) => { + // Const parameters don't impose constraints. + } + } } - types.extend(substs.types()); } Component::EscapingProjection(more_components) => { diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index bbda3d2fdbf..ee660328485 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -67,6 +67,7 @@ use crate::hir; use crate::traits::ObligationCause; use crate::ty::outlives::Component; use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable}; +use crate::ty::subst::UnpackedKind; impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// Registers that the given region obligation must be resolved @@ -430,13 +431,18 @@ where if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer { debug!("projection_must_outlive: no declared bounds"); - for component_ty in projection_ty.substs.types() { - self.type_must_outlive(origin.clone(), component_ty, region); - } - - for r in projection_ty.substs.regions() { - self.delegate - .push_sub_region_constraint(origin.clone(), region, r); + for k in projection_ty.substs { + match k.unpack() { + UnpackedKind::Lifetime(lt) => { + self.delegate.push_sub_region_constraint(origin.clone(), region, lt); + } + UnpackedKind::Type(ty) => { + self.type_must_outlive(origin.clone(), ty, region); + } + UnpackedKind::Const(_) => { + // Const parameters don't impose constraints. + } + } } return; diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b549986777c..a03d33a3ef5 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -81,7 +81,7 @@ use rustc::hir::def_id::DefId; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, RegionObligation, SuppressRegionErrors}; use rustc::ty::adjustment; -use rustc::ty::subst::SubstsRef; +use rustc::ty::subst::{SubstsRef, UnpackedKind}; use rustc::ty::{self, Ty}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; @@ -1407,13 +1407,19 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { let origin = infer::ParameterInScope(origin, expr_span); - for region in substs.regions() { - self.sub_regions(origin.clone(), expr_region, region); - } - - for ty in substs.types() { - let ty = self.resolve_type(ty); - self.type_must_outlive(origin.clone(), ty, expr_region); + for kind in substs { + match kind.unpack() { + UnpackedKind::Lifetime(lt) => { + self.sub_regions(origin.clone(), expr_region, lt); + } + UnpackedKind::Type(ty) => { + let ty = self.resolve_type(ty); + self.type_must_outlive(origin.clone(), ty, expr_region); + } + UnpackedKind::Const(_) => { + // Const parameters don't impose constraints. + } + } } } }