diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs index d44f2ec95492f..c6e7147c58abe 100644 --- a/src/librustc/infer/higher_ranked/mod.rs +++ b/src/librustc/infer/higher_ranked/mod.rs @@ -417,7 +417,7 @@ 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::new(0), *a_br)); } } span_bug!( diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index ceda72dcd7ae0..e5bb63f5d1f85 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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::new(0); 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) -> Region { let i = index.get(); index.set(i + 1); - let depth = ty::DebruijnIndex::new(1); + let depth = ty::DebruijnIndex::new(0); Region::LateBoundAnon(depth, i) } @@ -137,14 +137,14 @@ impl Region { match self { Region::LateBound(debruijn, id, origin) => Region::LateBound( ty::DebruijnIndex { - depth: debruijn.depth - (depth - 1), + depth: debruijn.depth - depth, }, id, origin, ), Region::LateBoundAnon(debruijn, index) => Region::LateBoundAnon( ty::DebruijnIndex { - depth: debruijn.depth - (depth - 1), + depth: debruijn.depth - depth, }, index, ), @@ -1781,7 +1781,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { .map(|(i, input)| { let mut gather = GatherLifetimes { map: self.map, - binder_depth: 1, + binder_depth: 0, have_bound_regions: false, lifetimes: FxHashSet(), }; diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 8071cd0c639da..d98b5fa35fdab 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -292,7 +292,7 @@ impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> { RegionFolder { tcx, skipped_regions, - current_depth: 1, + current_depth: 0, fld_r, } } @@ -448,7 +448,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let mut counter = 0; Binder(self.replace_late_bound_regions(sig, |_| { counter += 1; - self.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrAnon(counter))) + self.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(0), ty::BrAnon(counter))) }).0) } } @@ -460,7 +460,7 @@ impl<'a, 'gcx, 'tcx> RegionReplacer<'a, 'gcx, 'tcx> { { RegionReplacer { tcx, - current_depth: 1, + current_depth: 0, fld_r, map: BTreeMap::default() } @@ -478,7 +478,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionReplacer<'a, 'gcx, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if !t.has_regions_escaping_depth(self.current_depth-1) { + if !t.has_regions_escaping_depth(self.current_depth) { return t; } @@ -635,7 +635,7 @@ struct LateBoundRegionsCollector { impl LateBoundRegionsCollector { fn new(just_constrained: bool) -> Self { LateBoundRegionsCollector { - current_depth: 1, + current_depth: 0, regions: FxHashSet(), just_constrained, } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index ed04d41ba1457..12e15129cbaeb 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1156,7 +1156,6 @@ impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> { impl DebruijnIndex { pub fn new(depth: u32) -> DebruijnIndex { - assert!(depth > 0); DebruijnIndex { depth: depth } } @@ -1188,11 +1187,11 @@ impl RegionKind { } } - /// Returns the depth of `self` from the (1-based) binding level `depth` + /// Returns the depth of `self` from the (0-based) binding level `depth` pub fn from_depth(&self, depth: u32) -> RegionKind { match *self { ty::ReLateBound(debruijn, r) => ty::ReLateBound(DebruijnIndex { - depth: debruijn.depth - (depth - 1) + depth: debruijn.depth - depth }, r), r => r } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 22f851a908b25..17b1e4be2082c 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -589,7 +589,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { -> Option>> { 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::new(0), 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 { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index d27cda4040e56..6f99b6ecf5ebf 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -497,7 +497,7 @@ impl PrintContext { name) } }; - tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), br)) + tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(0), br)) }).0; start_or_continue(f, "", "> ")?; diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 9efd8844977f9..729960a7655d4 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -327,7 +327,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, ty::DebruijnIndex::new(0)); self.infcx.tcx.mk_imm_ref(r, self.tcx().types.isize) } @@ -484,7 +484,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, ty::DebruijnIndex::new(1)); env.t_fn(&[t_ptr_bound2], env.t_nil()) }; @@ -521,7 +521,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, ty::DebruijnIndex::new(1)); env.t_pair(t_rptr_bound1, env.t_fn(&[t_rptr_bound2], env.t_nil())) }; @@ -549,10 +549,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, ty::DebruijnIndex::new(0)); 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, ty::DebruijnIndex::new(1)); assert!(t_rptr_bound2.has_escaping_regions()); // t_fn = fn(A) @@ -568,7 +568,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, ty::DebruijnIndex::new(0)); // type t_source<'a> = fn(&'a isize) let t_source = { @@ -583,7 +583,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, ty::DebruijnIndex::new(1)); env.t_fn(&[t_rptr_bound2], env.t_nil()) }; diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index e83e73c8ae757..8f1102c1e4791 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -425,7 +425,7 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, let tcx = cx.tcx; let sig = substs.generator_poly_sig(def_id, cx.tcx); - let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv); + let env_region = ty::ReLateBound(ty::DebruijnIndex::new(0), ty::BrEnv); let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty); sig.map_bound(|sig| { diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 377e3a891840f..006ccc3c6d1d9 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -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::new(0), 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::new(0), ty::BrAnon(0))), param(0))], tcx.types.u64),