Skip to content

Commit 8bd4bff

Browse files
nikomatsakiscsmoe
andcommitted
stop invoking DebruijnIndex::new directly
Co-authored-by: csmoe <[email protected]>
1 parent b5018de commit 8bd4bff

File tree

8 files changed

+20
-21
lines changed

8 files changed

+20
-21
lines changed

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
417417
{
418418
for (a_br, a_r) in a_map {
419419
if *a_r == r {
420-
return infcx.tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), *a_br));
420+
return infcx.tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
421+
*a_br));
421422
}
422423
}
423424
span_bug!(

src/librustc/middle/resolve_lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Region {
9898
}
9999

100100
fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (hir::LifetimeName, Region) {
101-
let depth = ty::DebruijnIndex::new(1);
101+
let depth = ty::DebruijnIndex::INNERMOST;
102102
let def_id = hir_map.local_def_id(def.lifetime.id);
103103
let origin = LifetimeDefOrigin::from_is_in_band(def.in_band);
104104
(def.lifetime.name, Region::LateBound(depth, def_id, origin))
@@ -107,7 +107,7 @@ impl Region {
107107
fn late_anon(index: &Cell<u32>) -> Region {
108108
let i = index.get();
109109
index.set(i + 1);
110-
let depth = ty::DebruijnIndex::new(1);
110+
let depth = ty::DebruijnIndex::INNERMOST;
111111
Region::LateBoundAnon(depth, i)
112112
}
113113

src/librustc/ty/sty.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
10241024
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy, PartialOrd, Ord)]
10251025
pub struct DebruijnIndex {
10261026
/// We maintain the invariant that this is never 0. So 1 indicates
1027-
/// the innermost binder. To ensure this, create with `DebruijnIndex::new`.
1027+
/// the innermost binder.
10281028
pub depth: u32,
10291029
}
10301030

@@ -1261,11 +1261,6 @@ impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> {
12611261
impl DebruijnIndex {
12621262
pub const INNERMOST: DebruijnIndex = DebruijnIndex { depth: 1 };
12631263

1264-
pub fn new(depth: u32) -> DebruijnIndex {
1265-
assert!(depth > 0);
1266-
DebruijnIndex { depth: depth }
1267-
}
1268-
12691264
/// Returns the resulting index when this value is moved into
12701265
/// `amount` number of new binders. So e.g. if you had
12711266
///

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
555555
-> Option<ty::Binder<Ty<'tcx>>>
556556
{
557557
let closure_ty = self.mk_closure(closure_def_id, closure_substs);
558-
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
558+
let env_region = ty::ReLateBound(ty::DebruijnIndex::INNERMOST, ty::BrEnv);
559559
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self);
560560
let closure_kind = closure_kind_ty.to_opt_closure_kind()?;
561561
let env_ty = match closure_kind {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl PrintContext {
526526
ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name)
527527
}
528528
};
529-
tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), br))
529+
tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST, br))
530530
}).0;
531531
start_or_continue(f, "", "> ")?;
532532

src/librustc_codegen_llvm/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
425425
let tcx = cx.tcx;
426426
let sig = substs.poly_sig(def_id, cx.tcx);
427427

428-
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
428+
let env_region = ty::ReLateBound(ty::DebruijnIndex::INNERMOST, ty::BrEnv);
429429
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
430430

431431
sig.map_bound(|sig| {

src/librustc_driver/test.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ fn test_env_with_pool<F>(
183183
});
184184
}
185185

186+
const D1: ty::DebruijnIndex = ty::DebruijnIndex::INNERMOST;
187+
const D2: ty::DebruijnIndex = D1.shifted_in(1);
188+
186189
impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
187190
pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
188191
self.infcx.tcx
@@ -332,7 +335,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
332335
}
333336

334337
pub fn t_rptr_late_bound(&self, id: u32) -> Ty<'tcx> {
335-
let r = self.re_late_bound_with_debruijn(id, ty::DebruijnIndex::new(1));
338+
let r = self.re_late_bound_with_debruijn(id, D1);
336339
self.infcx.tcx.mk_imm_ref(r, self.tcx().types.isize)
337340
}
338341

@@ -489,7 +492,7 @@ fn subst_ty_renumber_bound() {
489492

490493
// t_expected = fn(&'a isize)
491494
let t_expected = {
492-
let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(2));
495+
let t_ptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
493496
env.t_fn(&[t_ptr_bound2], env.t_nil())
494497
};
495498

@@ -526,7 +529,7 @@ fn subst_ty_renumber_some_bounds() {
526529
//
527530
// but not that the Debruijn index is different in the different cases.
528531
let t_expected = {
529-
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(2));
532+
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
530533
env.t_pair(t_rptr_bound1, env.t_fn(&[t_rptr_bound2], env.t_nil()))
531534
};
532535

@@ -554,10 +557,10 @@ fn escaping() {
554557
let t_rptr_free1 = env.t_rptr_free(1);
555558
assert!(!t_rptr_free1.has_escaping_regions());
556559

557-
let t_rptr_bound1 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(1));
560+
let t_rptr_bound1 = env.t_rptr_late_bound_with_debruijn(1, D1);
558561
assert!(t_rptr_bound1.has_escaping_regions());
559562

560-
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(2));
563+
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
561564
assert!(t_rptr_bound2.has_escaping_regions());
562565

563566
// t_fn = fn(A)
@@ -573,7 +576,7 @@ fn escaping() {
573576
#[test]
574577
fn subst_region_renumber_region() {
575578
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
576-
let re_bound1 = env.re_late_bound_with_debruijn(1, ty::DebruijnIndex::new(1));
579+
let re_bound1 = env.re_late_bound_with_debruijn(1, D1);
577580

578581
// type t_source<'a> = fn(&'a isize)
579582
let t_source = {
@@ -588,7 +591,7 @@ fn subst_region_renumber_region() {
588591
//
589592
// but not that the Debruijn index is different in the different cases.
590593
let t_expected = {
591-
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, ty::DebruijnIndex::new(2));
594+
let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, D2);
592595
env.t_fn(&[t_rptr_bound2], env.t_nil())
593596
};
594597

src/librustc_typeck/check/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
119119
"pref_align_of" | "min_align_of" => (1, Vec::new(), tcx.types.usize),
120120
"size_of_val" | "min_align_of_val" => {
121121
(1, vec![
122-
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
122+
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
123123
ty::BrAnon(0))),
124124
param(0))
125125
], tcx.types.usize)
@@ -298,7 +298,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
298298
"unlikely" => (0, vec![tcx.types.bool], tcx.types.bool),
299299

300300
"discriminant_value" => (1, vec![
301-
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
301+
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::INNERMOST,
302302
ty::BrAnon(0))),
303303
param(0))], tcx.types.u64),
304304

0 commit comments

Comments
 (0)