|
1 |
| -use crate::ty::{self, Lift, Region, TyCtxt}; |
| 1 | +//! This module handles the relationships between "free regions", i.e., lifetime parameters. |
| 2 | +//! Ordinarily, free regions are unrelated to one another, but they can be related via implied |
| 3 | +//! or explicit bounds. In that case, we track the bounds using the `TransitiveRelation` type, |
| 4 | +//! and use that to decide when one free region outlives another, and so forth. |
| 5 | +
|
2 | 6 | use rustc_data_structures::transitive_relation::TransitiveRelation;
|
| 7 | +use rustc_hir::def_id::DefId; |
| 8 | +use rustc_middle::middle::region; |
| 9 | +use rustc_middle::ty::{self, Lift, Region, TyCtxt}; |
| 10 | + |
| 11 | +/// Combines a `region::ScopeTree` (which governs relationships between |
| 12 | +/// scopes) and a `FreeRegionMap` (which governs relationships between |
| 13 | +/// free regions) to yield a complete relation between concrete |
| 14 | +/// regions. |
| 15 | +/// |
| 16 | +/// This stuff is a bit convoluted and should be refactored, but as we |
| 17 | +/// transition to NLL, it'll all go away anyhow. |
| 18 | +pub struct RegionRelations<'a, 'tcx> { |
| 19 | + pub tcx: TyCtxt<'tcx>, |
| 20 | + |
| 21 | + /// The context used to fetch the region maps. |
| 22 | + pub context: DefId, |
| 23 | + |
| 24 | + /// The region maps for the given context. |
| 25 | + pub region_scope_tree: &'a region::ScopeTree, |
| 26 | + |
| 27 | + /// Free-region relationships. |
| 28 | + pub free_regions: &'a FreeRegionMap<'tcx>, |
| 29 | +} |
| 30 | + |
| 31 | +impl<'a, 'tcx> RegionRelations<'a, 'tcx> { |
| 32 | + pub fn new( |
| 33 | + tcx: TyCtxt<'tcx>, |
| 34 | + context: DefId, |
| 35 | + region_scope_tree: &'a region::ScopeTree, |
| 36 | + free_regions: &'a FreeRegionMap<'tcx>, |
| 37 | + ) -> Self { |
| 38 | + Self { tcx, context, region_scope_tree, free_regions } |
| 39 | + } |
| 40 | + |
| 41 | + pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> { |
| 42 | + self.free_regions.lub_free_regions(self.tcx, r_a, r_b) |
| 43 | + } |
| 44 | +} |
3 | 45 |
|
4 | 46 | #[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default, HashStable)]
|
5 | 47 | pub struct FreeRegionMap<'tcx> {
|
|
0 commit comments