@@ -1289,53 +1289,6 @@ impl<'tcx> ParamConst {
12891289 }
12901290}
12911291
1292- rustc_index:: newtype_index! {
1293- /// A [De Bruijn index][dbi] is a standard means of representing
1294- /// regions (and perhaps later types) in a higher-ranked setting. In
1295- /// particular, imagine a type like this:
1296- ///
1297- /// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char)
1298- /// ^ ^ | | |
1299- /// | | | | |
1300- /// | +------------+ 0 | |
1301- /// | | |
1302- /// +----------------------------------+ 1 |
1303- /// | |
1304- /// +----------------------------------------------+ 0
1305- ///
1306- /// In this type, there are two binders (the outer fn and the inner
1307- /// fn). We need to be able to determine, for any given region, which
1308- /// fn type it is bound by, the inner or the outer one. There are
1309- /// various ways you can do this, but a De Bruijn index is one of the
1310- /// more convenient and has some nice properties. The basic idea is to
1311- /// count the number of binders, inside out. Some examples should help
1312- /// clarify what I mean.
1313- ///
1314- /// Let's start with the reference type `&'b isize` that is the first
1315- /// argument to the inner function. This region `'b` is assigned a De
1316- /// Bruijn index of 0, meaning "the innermost binder" (in this case, a
1317- /// fn). The region `'a` that appears in the second argument type (`&'a
1318- /// isize`) would then be assigned a De Bruijn index of 1, meaning "the
1319- /// second-innermost binder". (These indices are written on the arrays
1320- /// in the diagram).
1321- ///
1322- /// What is interesting is that De Bruijn index attached to a particular
1323- /// variable will vary depending on where it appears. For example,
1324- /// the final type `&'a char` also refers to the region `'a` declared on
1325- /// the outermost fn. But this time, this reference is not nested within
1326- /// any other binders (i.e., it is not an argument to the inner fn, but
1327- /// rather the outer one). Therefore, in this case, it is assigned a
1328- /// De Bruijn index of 0, because the innermost binder in that location
1329- /// is the outer fn.
1330- ///
1331- /// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index
1332- #[ derive( HashStable ) ]
1333- pub struct DebruijnIndex {
1334- DEBUG_FORMAT = "DebruijnIndex({})" ,
1335- const INNERMOST = 0 ,
1336- }
1337- }
1338-
13391292pub type Region < ' tcx > = & ' tcx RegionKind ;
13401293
13411294/// Representation of regions. Note that the NLL checker uses a distinct
@@ -1450,7 +1403,7 @@ pub enum RegionKind {
14501403
14511404 /// Region bound in a function scope, which will be substituted when the
14521405 /// function is called.
1453- ReLateBound ( DebruijnIndex , BoundRegion ) ,
1406+ ReLateBound ( ty :: DebruijnIndex , BoundRegion ) ,
14541407
14551408 /// When checking a function body, the types of all arguments and so forth
14561409 /// that refer to bound region parameters are modified to refer to free
@@ -1614,65 +1567,6 @@ impl<'tcx> PolyExistentialProjection<'tcx> {
16141567 }
16151568}
16161569
1617- impl DebruijnIndex {
1618- /// Returns the resulting index when this value is moved into
1619- /// `amount` number of new binders. So, e.g., if you had
1620- ///
1621- /// for<'a> fn(&'a x)
1622- ///
1623- /// and you wanted to change it to
1624- ///
1625- /// for<'a> fn(for<'b> fn(&'a x))
1626- ///
1627- /// you would need to shift the index for `'a` into a new binder.
1628- #[ must_use]
1629- pub fn shifted_in ( self , amount : u32 ) -> DebruijnIndex {
1630- DebruijnIndex :: from_u32 ( self . as_u32 ( ) + amount)
1631- }
1632-
1633- /// Update this index in place by shifting it "in" through
1634- /// `amount` number of binders.
1635- pub fn shift_in ( & mut self , amount : u32 ) {
1636- * self = self . shifted_in ( amount) ;
1637- }
1638-
1639- /// Returns the resulting index when this value is moved out from
1640- /// `amount` number of new binders.
1641- #[ must_use]
1642- pub fn shifted_out ( self , amount : u32 ) -> DebruijnIndex {
1643- DebruijnIndex :: from_u32 ( self . as_u32 ( ) - amount)
1644- }
1645-
1646- /// Update in place by shifting out from `amount` binders.
1647- pub fn shift_out ( & mut self , amount : u32 ) {
1648- * self = self . shifted_out ( amount) ;
1649- }
1650-
1651- /// Adjusts any De Bruijn indices so as to make `to_binder` the
1652- /// innermost binder. That is, if we have something bound at `to_binder`,
1653- /// it will now be bound at INNERMOST. This is an appropriate thing to do
1654- /// when moving a region out from inside binders:
1655- ///
1656- /// ```
1657- /// for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
1658- /// // Binder: D3 D2 D1 ^^
1659- /// ```
1660- ///
1661- /// Here, the region `'a` would have the De Bruijn index D3,
1662- /// because it is the bound 3 binders out. However, if we wanted
1663- /// to refer to that region `'a` in the second argument (the `_`),
1664- /// those two binders would not be in scope. In that case, we
1665- /// might invoke `shift_out_to_binder(D3)`. This would adjust the
1666- /// De Bruijn index of `'a` to D1 (the innermost binder).
1667- ///
1668- /// If we invoke `shift_out_to_binder` and the region is in fact
1669- /// bound by one of the binders we are shifting out of, that is an
1670- /// error (and should fail an assertion failure).
1671- pub fn shifted_out_to_binder ( self , to_binder : DebruijnIndex ) -> Self {
1672- self . shifted_out ( to_binder. as_u32 ( ) - INNERMOST . as_u32 ( ) )
1673- }
1674- }
1675-
16761570/// Region utilities
16771571impl RegionKind {
16781572 /// Is this region named by the user?
@@ -1703,7 +1597,7 @@ impl RegionKind {
17031597 }
17041598 }
17051599
1706- pub fn bound_at_or_above_binder ( & self , index : DebruijnIndex ) -> bool {
1600+ pub fn bound_at_or_above_binder ( & self , index : ty :: DebruijnIndex ) -> bool {
17071601 match * self {
17081602 ty:: ReLateBound ( debruijn, _) => debruijn >= index,
17091603 _ => false ,
0 commit comments