stop invoking DebruijnIndex::new
directly
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
This commit is contained in:
parent
b5018de0ed
commit
8bd4bffe50
@ -417,7 +417,8 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
|
||||
{
|
||||
for (a_br, a_r) in a_map {
|
||||
if *a_r == r {
|
||||
return infcx.tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), *a_br));
|
||||
return infcx.tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
|
||||
*a_br));
|
||||
}
|
||||
}
|
||||
span_bug!(
|
||||
|
@ -98,7 +98,7 @@ impl Region {
|
||||
}
|
||||
|
||||
fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (hir::LifetimeName, Region) {
|
||||
let depth = ty::DebruijnIndex::new(1);
|
||||
let depth = ty::DebruijnIndex::INNERMOST;
|
||||
let def_id = hir_map.local_def_id(def.lifetime.id);
|
||||
let origin = LifetimeDefOrigin::from_is_in_band(def.in_band);
|
||||
(def.lifetime.name, Region::LateBound(depth, def_id, origin))
|
||||
@ -107,7 +107,7 @@ impl Region {
|
||||
fn late_anon(index: &Cell<u32>) -> Region {
|
||||
let i = index.get();
|
||||
index.set(i + 1);
|
||||
let depth = ty::DebruijnIndex::new(1);
|
||||
let depth = ty::DebruijnIndex::INNERMOST;
|
||||
Region::LateBoundAnon(depth, i)
|
||||
}
|
||||
|
||||
|
@ -1024,7 +1024,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
||||
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy, PartialOrd, Ord)]
|
||||
pub struct DebruijnIndex {
|
||||
/// We maintain the invariant that this is never 0. So 1 indicates
|
||||
/// the innermost binder. To ensure this, create with `DebruijnIndex::new`.
|
||||
/// the innermost binder.
|
||||
pub depth: u32,
|
||||
}
|
||||
|
||||
@ -1261,11 +1261,6 @@ impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> {
|
||||
impl DebruijnIndex {
|
||||
pub const INNERMOST: DebruijnIndex = DebruijnIndex { depth: 1 };
|
||||
|
||||
pub fn new(depth: u32) -> DebruijnIndex {
|
||||
assert!(depth > 0);
|
||||
DebruijnIndex { depth: depth }
|
||||
}
|
||||
|
||||
/// Returns the resulting index when this value is moved into
|
||||
/// `amount` number of new binders. So e.g. if you had
|
||||
///
|
||||
|
@ -555,7 +555,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
-> Option<ty::Binder<Ty<'tcx>>>
|
||||
{
|
||||
let closure_ty = self.mk_closure(closure_def_id, closure_substs);
|
||||
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
|
||||
let env_region = ty::ReLateBound(ty::DebruijnIndex::INNERMOST, ty::BrEnv);
|
||||
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self);
|
||||
let closure_kind = closure_kind_ty.to_opt_closure_kind()?;
|
||||
let env_ty = match closure_kind {
|
||||
|
@ -526,7 +526,7 @@ impl PrintContext {
|
||||
ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name)
|
||||
}
|
||||
};
|
||||
tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), br))
|
||||
tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST, br))
|
||||
}).0;
|
||||
start_or_continue(f, "", "> ")?;
|
||||
|
||||
|
@ -425,7 +425,7 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
let tcx = cx.tcx;
|
||||
let sig = substs.poly_sig(def_id, cx.tcx);
|
||||
|
||||
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
|
||||
let env_region = ty::ReLateBound(ty::DebruijnIndex::INNERMOST, ty::BrEnv);
|
||||
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
|
||||
|
||||
sig.map_bound(|sig| {
|
||||
|
@ -183,6 +183,9 @@ fn test_env_with_pool<F>(
|
||||
});
|
||||
}
|
||||
|
||||
const D1: ty::DebruijnIndex = ty::DebruijnIndex::INNERMOST;
|
||||
const D2: ty::DebruijnIndex = D1.shifted_in(1);
|
||||
|
||||
impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
@ -332,7 +335,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn t_rptr_late_bound(&self, id: u32) -> Ty<'tcx> {
|
||||
let r = self.re_late_bound_with_debruijn(id, ty::DebruijnIndex::new(1));
|
||||
let r = self.re_late_bound_with_debruijn(id, D1);
|
||||
self.infcx.tcx.mk_imm_ref(r, self.tcx().types.isize)
|
||||
}
|
||||
|
||||
@ -489,7 +492,7 @@ fn subst_ty_renumber_bound() {
|
||||
|
||||
// t_expected = fn(&'a isize)
|
||||
let t_expected = {
|
||||
let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(2));
|
||||
let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
|
||||
env.t_fn(&[t_ptr_bound2], env.t_nil())
|
||||
};
|
||||
|
||||
@ -526,7 +529,7 @@ fn subst_ty_renumber_some_bounds() {
|
||||
//
|
||||
// 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, ty::DebruijnIndex::new(2));
|
||||
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()))
|
||||
};
|
||||
|
||||
@ -554,10 +557,10 @@ fn escaping() {
|
||||
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, ty::DebruijnIndex::new(1));
|
||||
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, ty::DebruijnIndex::new(2));
|
||||
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
|
||||
assert!(t_rptr_bound2.has_escaping_regions());
|
||||
|
||||
// t_fn = fn(A)
|
||||
@ -573,7 +576,7 @@ fn escaping() {
|
||||
#[test]
|
||||
fn subst_region_renumber_region() {
|
||||
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let re_bound1 = env.re_late_bound_with_debruijn(1, ty::DebruijnIndex::new(1));
|
||||
let re_bound1 = env.re_late_bound_with_debruijn(1, D1);
|
||||
|
||||
// type t_source<'a> = fn(&'a isize)
|
||||
let t_source = {
|
||||
@ -588,7 +591,7 @@ fn subst_region_renumber_region() {
|
||||
//
|
||||
// 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, ty::DebruijnIndex::new(2));
|
||||
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
|
||||
env.t_fn(&[t_rptr_bound2], env.t_nil())
|
||||
};
|
||||
|
||||
|
@ -119,7 +119,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
"pref_align_of" | "min_align_of" => (1, Vec::new(), tcx.types.usize),
|
||||
"size_of_val" | "min_align_of_val" => {
|
||||
(1, vec![
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
|
||||
ty::BrAnon(0))),
|
||||
param(0))
|
||||
], tcx.types.usize)
|
||||
@ -298,7 +298,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
"unlikely" => (0, vec![tcx.types.bool], tcx.types.bool),
|
||||
|
||||
"discriminant_value" => (1, vec![
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
|
||||
ty::BrAnon(0))),
|
||||
param(0))], tcx.types.u64),
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user