///
/// you would need to shift the index for `'a` into 1 new binder.
#[must_use]
- pub const fn shifted_in(self, amount: u32) -> DebruijnIndex {
+ pub fn shifted_in(self, amount: u32) -> DebruijnIndex {
unsafe {
DebruijnIndex::from_u32_unchecked(self.as_u32() + amount)
}
/// Returns the resulting index when this value is moved out from
/// `amount` number of new binders.
#[must_use]
- pub const fn shifted_out(self, amount: u32) -> DebruijnIndex {
+ pub fn shifted_out(self, amount: u32) -> DebruijnIndex {
unsafe {
DebruijnIndex::from_u32_unchecked(self.as_u32() - amount)
}
@debug_format [$debug_format:tt]) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
$v struct $type {
- private: u32
+ private: ::std::num::NonZeroU32
}
impl $type {
#[inline]
$v const unsafe fn from_u32_unchecked(value: u32) -> Self {
- $type { private: value }
+ $type { private: ::std::num::NonZeroU32::new_unchecked(value + 1) }
}
/// Extract value of this index as an integer.
/// Extract value of this index as a usize.
#[inline]
- $v const fn as_u32(self) -> u32 {
- self.private
+ $v fn as_u32(self) -> u32 {
+ self.private.get() - 1
}
/// Extract value of this index as a u32.
#[inline]
- $v const fn as_usize(self) -> usize {
+ $v fn as_usize(self) -> usize {
self.as_u32() as usize
}
}
});
}
-const D1: ty::DebruijnIndex = ty::INNERMOST;
-const D2: ty::DebruijnIndex = D1.shifted_in(1);
+fn d1() -> ty::DebruijnIndex {
+ ty::INNERMOST
+}
+
+fn d2() -> ty::DebruijnIndex {
+ d1().shifted_in(1)
+}
impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
}
pub fn t_rptr_late_bound(&self, id: u32) -> Ty<'tcx> {
- let r = self.re_late_bound_with_debruijn(id, D1);
+ let r = self.re_late_bound_with_debruijn(id, d1());
self.infcx.tcx.mk_imm_ref(r, self.tcx().types.isize)
}
// t_expected = fn(&'a isize)
let t_expected = {
- let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
+ let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, d2());
env.t_fn(&[t_ptr_bound2], env.t_nil())
};
//
// but not that the Debruijn index is different in the different cases.
let t_expected = {
- let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
+ let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, d2());
env.t_pair(t_rptr_bound1, env.t_fn(&[t_rptr_bound2], env.t_nil()))
};
let t_rptr_free1 = env.t_rptr_free(1);
assert!(!t_rptr_free1.has_escaping_regions());
- let t_rptr_bound1 = env.t_rptr_late_bound_with_debruijn(1, D1);
+ let t_rptr_bound1 = env.t_rptr_late_bound_with_debruijn(1, d1());
assert!(t_rptr_bound1.has_escaping_regions());
- let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
+ let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, d2());
assert!(t_rptr_bound2.has_escaping_regions());
// t_fn = fn(A)
#[test]
fn subst_region_renumber_region() {
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
- let re_bound1 = env.re_late_bound_with_debruijn(1, D1);
+ let re_bound1 = env.re_late_bound_with_debruijn(1, d1());
// type t_source<'a> = fn(&'a isize)
let t_source = {
//
// but not that the Debruijn index is different in the different cases.
let t_expected = {
- let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
+ let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, d2());
env.t_fn(&[t_rptr_bound2], env.t_nil())
};