-pub fn ast_region_to_region<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
- lifetime: &hir::Lifetime)
- -> &'tcx ty::Region {
- let r = match tcx.named_region_map.defs.get(&lifetime.id) {
- None => {
- // should have been recorded by the `resolve_lifetime` pass
- span_bug!(lifetime.span, "unresolved lifetime");
- }
-
- Some(&rl::DefStaticRegion) => {
- ty::ReStatic
- }
-
- Some(&rl::DefLateBoundRegion(debruijn, id)) => {
- // If this region is declared on a function, it will have
- // an entry in `late_bound`, but if it comes from
- // `for<'a>` in some type or something, it won't
- // necessarily have one. In that case though, we won't be
- // changed from late to early bound, so we can just
- // substitute false.
- let issue_32330 = tcx.named_region_map
- .late_bound
- .get(&id)
- .cloned()
- .unwrap_or(ty::Issue32330::WontChange);
- ty::ReLateBound(debruijn, ty::BrNamed(tcx.hir.local_def_id(id),
- lifetime.name,
- issue_32330))
- }
-
- Some(&rl::DefEarlyBoundRegion(index, _)) => {
- ty::ReEarlyBound(ty::EarlyBoundRegion {
- index: index,
- name: lifetime.name
- })
- }
-
- Some(&rl::DefFreeRegion(scope, id)) => {
- // As in DefLateBoundRegion above, could be missing for some late-bound
- // regions, but also for early-bound regions.
- let issue_32330 = tcx.named_region_map
- .late_bound
- .get(&id)
- .cloned()
- .unwrap_or(ty::Issue32330::WontChange);
- ty::ReFree(ty::FreeRegion {
- scope: scope.to_code_extent(&tcx.region_maps),
- bound_region: ty::BrNamed(tcx.hir.local_def_id(id),
- lifetime.name,
- issue_32330)
- })
-
- // (*) -- not late-bound, won't change
- }
- };
-
- debug!("ast_region_to_region(lifetime={:?} id={}) yields {:?}",
- lifetime,
- lifetime.id,
- r);
-
- tcx.mk_region(r)
-}
-