Skip to content

Commit 042c296

Browse files
committed
simplify DebruijnIndex APIs to just u32
1 parent 8abe633 commit 042c296

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

chalk-ir/src/lib.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -371,35 +371,18 @@ pub struct DebruijnIndex {
371371
depth: u32,
372372
}
373373

374-
impl From<u32> for DebruijnIndex {
375-
fn from(depth: u32) -> Self {
376-
Self::from_u32(depth)
377-
}
378-
}
379-
380-
impl From<usize> for DebruijnIndex {
381-
fn from(depth: usize) -> Self {
382-
assert!(depth < (std::u32::MAX as usize));
383-
Self::from_u32(depth as u32)
384-
}
385-
}
386-
387374
impl DebruijnIndex {
388375
pub const INNERMOST: DebruijnIndex = DebruijnIndex { depth: 0 };
389376
pub const ONE: DebruijnIndex = DebruijnIndex { depth: 1 };
390377

391-
pub fn from_u32(depth: u32) -> Self {
378+
pub fn new(depth: u32) -> Self {
392379
DebruijnIndex { depth }
393380
}
394381

395-
pub fn as_u32(self) -> u32 {
382+
pub fn depth(self) -> u32 {
396383
self.depth
397384
}
398385

399-
pub fn as_usize(self) -> usize {
400-
self.depth as usize
401-
}
402-
403386
/// True if the binder identified by this index is within the
404387
/// binder identified by the index `outer_binder`.
405388
///
@@ -463,7 +446,7 @@ impl DebruijnIndex {
463446
/// innermost binder, has index 3).
464447
#[must_use]
465448
pub fn shifted_in_from(self, outer_binder: DebruijnIndex) -> DebruijnIndex {
466-
DebruijnIndex::from(self.as_usize() + outer_binder.as_usize())
449+
DebruijnIndex::new(self.depth() + outer_binder.depth())
467450
}
468451

469452
/// Returns the resulting index when this value is moved out from
@@ -508,9 +491,7 @@ impl DebruijnIndex {
508491
if self.within(outer_binder) {
509492
None
510493
} else {
511-
Some(DebruijnIndex::from(
512-
self.as_usize() - outer_binder.as_usize(),
513-
))
494+
Some(DebruijnIndex::new(self.depth() - outer_binder.depth()))
514495
}
515496
}
516497
}

chalk-ir/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! ty {
3535
};
3636

3737
(bound $d:tt $b:tt) => {
38-
$crate::TyData::BoundVar($crate::BoundVar::new($crate::DebruijnIndex::from_u32($d), $b)).intern(&chalk_ir::interner::ChalkIr)
38+
$crate::TyData::BoundVar($crate::BoundVar::new($crate::DebruijnIndex::new($d), $b)).intern(&chalk_ir::interner::ChalkIr)
3939
};
4040

4141
(bound $b:expr) => {
@@ -75,7 +75,7 @@ macro_rules! lifetime {
7575
};
7676

7777
(bound $d:tt $b:tt) => {
78-
$crate::LifetimeData::BoundVar($crate::BoundVar::new($crate::DebruijnIndex::from_u32($d), $b)).intern(&chalk_ir::interner::ChalkIr)
78+
$crate::LifetimeData::BoundVar($crate::BoundVar::new($crate::DebruijnIndex::new($d), $b)).intern(&chalk_ir::interner::ChalkIr)
7979
};
8080

8181
(bound $b:expr) => {

0 commit comments

Comments
 (0)