1
Fork 0

Clean up some generic substs handling

This commit is contained in:
varkor 2019-02-20 12:47:19 +00:00
parent 162405f222
commit 0da0457593
3 changed files with 35 additions and 18 deletions

View file

@ -381,10 +381,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
substs, substs,
item_def_id: _, item_def_id: _,
}) => { }) => {
for r in substs.regions() { for k in substs {
bound_region(r); 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) => { Component::EscapingProjection(more_components) => {

View file

@ -67,6 +67,7 @@ use crate::hir;
use crate::traits::ObligationCause; use crate::traits::ObligationCause;
use crate::ty::outlives::Component; use crate::ty::outlives::Component;
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable}; use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
use crate::ty::subst::UnpackedKind;
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
/// Registers that the given region obligation must be resolved /// 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 { if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
debug!("projection_must_outlive: no declared bounds"); debug!("projection_must_outlive: no declared bounds");
for component_ty in projection_ty.substs.types() { for k in projection_ty.substs {
self.type_must_outlive(origin.clone(), component_ty, region); match k.unpack() {
} UnpackedKind::Lifetime(lt) => {
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);
for r in projection_ty.substs.regions() { }
self.delegate UnpackedKind::Type(ty) => {
.push_sub_region_constraint(origin.clone(), region, r); self.type_must_outlive(origin.clone(), ty, region);
}
UnpackedKind::Const(_) => {
// Const parameters don't impose constraints.
}
}
} }
return; return;

View file

@ -81,7 +81,7 @@ use rustc::hir::def_id::DefId;
use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::outlives::env::OutlivesEnvironment;
use rustc::infer::{self, RegionObligation, SuppressRegionErrors}; use rustc::infer::{self, RegionObligation, SuppressRegionErrors};
use rustc::ty::adjustment; use rustc::ty::adjustment;
use rustc::ty::subst::SubstsRef; use rustc::ty::subst::{SubstsRef, UnpackedKind};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; 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); let origin = infer::ParameterInScope(origin, expr_span);
for region in substs.regions() { for kind in substs {
self.sub_regions(origin.clone(), expr_region, region); match kind.unpack() {
} UnpackedKind::Lifetime(lt) => {
self.sub_regions(origin.clone(), expr_region, lt);
for ty in substs.types() { }
let ty = self.resolve_type(ty); UnpackedKind::Type(ty) => {
self.type_must_outlive(origin.clone(), ty, expr_region); let ty = self.resolve_type(ty);
self.type_must_outlive(origin.clone(), ty, expr_region);
}
UnpackedKind::Const(_) => {
// Const parameters don't impose constraints.
}
}
} }
} }
} }