Skip to content

Commit abd6d0d

Browse files
committed
comments for defining_ty and compute_indices
Plus an extra assertion.
1 parent 75ac071 commit abd6d0d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/librustc_mir/borrow_check/nll/universal_regions.rs

+20
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,21 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
456456
}
457457
}
458458

459+
/// Returns the "defining type" of the current MIR:
460+
///
461+
/// - for functions, this is the `TyFnDef`;
462+
/// - for closures, this is the `TyClosure`;
463+
/// - for generators, this is the `TyGenerator`;
464+
/// - for constants, this is the type of value that gets produced.
465+
/// - FIXME. Constants are handled somewhat inelegantly; this gets
466+
/// patched in a later PR that has already landed on nll-master.
467+
///
468+
/// The key feature of the "defining type" is that it contains the
469+
/// information needed to derive all the universal regions that
470+
/// are in scope as well as the types of the inputs/output from
471+
/// the MIR. In general, early-bound universal regions appear free
472+
/// in the defining type and late-bound regions appear bound in
473+
/// the signature.
459474
fn defining_ty(&self) -> ty::Ty<'tcx> {
460475
let tcx = self.infcx.tcx;
461476
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> {
471486
.replace_free_regions_with_nll_infer_vars(FR, &defining_ty)
472487
}
473488

489+
/// Builds a hashmap that maps from the universal regions that are
490+
/// in scope (as a `ty::Region<'tcx>`) to their indices (as a
491+
/// `RegionVid`). The map returned by this function contains only
492+
/// the early-bound regions.
474493
fn compute_indices(
475494
&self,
476495
fr_static: RegionVid,
@@ -490,6 +509,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
490509
// that correspond to early-bound regions declared on
491510
// the `closure_base_def_id`.
492511
assert!(substs.substs.len() >= identity_substs.len());
512+
assert_eq!(substs.substs.regions().count(), identity_substs.regions().count());
493513
substs.substs
494514
}
495515
ty::TyFnDef(_, substs) => substs,

0 commit comments

Comments
 (0)