Skip to content

Commit 0da0457

Browse files
committed
Clean up some generic substs handling
1 parent 162405f commit 0da0457

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

src/librustc/infer/opaque_types/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
381381
substs,
382382
item_def_id: _,
383383
}) => {
384-
for r in substs.regions() {
385-
bound_region(r);
384+
for k in substs {
385+
match k.unpack() {
386+
UnpackedKind::Lifetime(lt) => bound_region(lt),
387+
UnpackedKind::Type(ty) => types.push(ty),
388+
UnpackedKind::Const(_) => {
389+
// Const parameters don't impose constraints.
390+
}
391+
}
386392
}
387-
types.extend(substs.types());
388393
}
389394

390395
Component::EscapingProjection(more_components) => {

src/librustc/infer/outlives/obligations.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use crate::hir;
6767
use crate::traits::ObligationCause;
6868
use crate::ty::outlives::Component;
6969
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
70+
use crate::ty::subst::UnpackedKind;
7071

7172
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
7273
/// Registers that the given region obligation must be resolved
@@ -430,13 +431,18 @@ where
430431
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
431432
debug!("projection_must_outlive: no declared bounds");
432433

433-
for component_ty in projection_ty.substs.types() {
434-
self.type_must_outlive(origin.clone(), component_ty, region);
435-
}
436-
437-
for r in projection_ty.substs.regions() {
438-
self.delegate
439-
.push_sub_region_constraint(origin.clone(), region, r);
434+
for k in projection_ty.substs {
435+
match k.unpack() {
436+
UnpackedKind::Lifetime(lt) => {
437+
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);
438+
}
439+
UnpackedKind::Type(ty) => {
440+
self.type_must_outlive(origin.clone(), ty, region);
441+
}
442+
UnpackedKind::Const(_) => {
443+
// Const parameters don't impose constraints.
444+
}
445+
}
440446
}
441447

442448
return;

src/librustc_typeck/check/regionck.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use rustc::hir::def_id::DefId;
8181
use rustc::infer::outlives::env::OutlivesEnvironment;
8282
use rustc::infer::{self, RegionObligation, SuppressRegionErrors};
8383
use rustc::ty::adjustment;
84-
use rustc::ty::subst::SubstsRef;
84+
use rustc::ty::subst::{SubstsRef, UnpackedKind};
8585
use rustc::ty::{self, Ty};
8686

8787
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -1407,13 +1407,19 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
14071407

14081408
let origin = infer::ParameterInScope(origin, expr_span);
14091409

1410-
for region in substs.regions() {
1411-
self.sub_regions(origin.clone(), expr_region, region);
1412-
}
1413-
1414-
for ty in substs.types() {
1415-
let ty = self.resolve_type(ty);
1416-
self.type_must_outlive(origin.clone(), ty, expr_region);
1410+
for kind in substs {
1411+
match kind.unpack() {
1412+
UnpackedKind::Lifetime(lt) => {
1413+
self.sub_regions(origin.clone(), expr_region, lt);
1414+
}
1415+
UnpackedKind::Type(ty) => {
1416+
let ty = self.resolve_type(ty);
1417+
self.type_must_outlive(origin.clone(), ty, expr_region);
1418+
}
1419+
UnpackedKind::Const(_) => {
1420+
// Const parameters don't impose constraints.
1421+
}
1422+
}
14171423
}
14181424
}
14191425
}

0 commit comments

Comments
 (0)