diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-12-12 19:46:36 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-12-13 12:20:28 -0500 |
| commit | abd6d0d76ec279378fa1ebf92c7c6b5dc6c28906 (patch) | |
| tree | 570025c6b027f2f9ac8d3699aaf0513de779bd48 | |
| parent | 75ac071cd6e14c887fbb7526da8958b53aaf7198 (diff) | |
| download | rust-abd6d0d76ec279378fa1ebf92c7c6b5dc6c28906.tar.gz rust-abd6d0d76ec279378fa1ebf92c7c6b5dc6c28906.zip | |
comments for `defining_ty` and `compute_indices`
Plus an extra assertion.
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/universal_regions.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index c8b5a258a70..5336bd271f5 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -456,6 +456,21 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { } } + /// Returns the "defining type" of the current MIR: + /// + /// - for functions, this is the `TyFnDef`; + /// - for closures, this is the `TyClosure`; + /// - for generators, this is the `TyGenerator`; + /// - for constants, this is the type of value that gets produced. + /// - FIXME. Constants are handled somewhat inelegantly; this gets + /// patched in a later PR that has already landed on nll-master. + /// + /// The key feature of the "defining type" is that it contains the + /// information needed to derive all the universal regions that + /// are in scope as well as the types of the inputs/output from + /// the MIR. In general, early-bound universal regions appear free + /// in the defining type and late-bound regions appear bound in + /// the signature. fn defining_ty(&self) -> ty::Ty<'tcx> { let tcx = self.infcx.tcx; let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); @@ -471,6 +486,10 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { .replace_free_regions_with_nll_infer_vars(FR, &defining_ty) } + /// Builds a hashmap that maps from the universal regions that are + /// in scope (as a `ty::Region<'tcx>`) to their indices (as a + /// `RegionVid`). The map returned by this function contains only + /// the early-bound regions. fn compute_indices( &self, fr_static: RegionVid, @@ -490,6 +509,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { // that correspond to early-bound regions declared on // the `closure_base_def_id`. assert!(substs.substs.len() >= identity_substs.len()); + assert_eq!(substs.substs.regions().count(), identity_substs.regions().count()); substs.substs } ty::TyFnDef(_, substs) => substs, |
