Skip to content

Commit

Permalink
Remove usize trait impls
Browse files Browse the repository at this point in the history
This removes `Add`/`AddAssign`/`Sub`/`SubAssign` with `usize` from
`VirtAddr` and `PhysAddr` (which are always 64-bit, even on 32-bit
platforms). This makes it possible to write code like:

```rust
let addr1 = PhysAddr::new(0x52);
let addr2 = addr1 + 3;
```

without getting a "multiple `impl`s" compiler error.

This is essentially the breaking change mentioned in
#293 (comment)

Signed-off-by: Joe Richey <[email protected]>
  • Loading branch information
josephlr committed Mar 28, 2022
1 parent d8edd3f commit 5bbc76e
Showing 1 changed file with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,6 @@ impl AddAssign<u64> for VirtAddr {
}
}

#[cfg(target_pointer_width = "64")]
impl Add<usize> for VirtAddr {
type Output = Self;
#[inline]
fn add(self, rhs: usize) -> Self::Output {
self + rhs as u64
}
}

#[cfg(target_pointer_width = "64")]
impl AddAssign<usize> for VirtAddr {
#[inline]
fn add_assign(&mut self, rhs: usize) {
self.add_assign(rhs as u64)
}
}

impl Sub<u64> for VirtAddr {
type Output = Self;
#[inline]
Expand All @@ -313,23 +296,6 @@ impl SubAssign<u64> for VirtAddr {
}
}

#[cfg(target_pointer_width = "64")]
impl Sub<usize> for VirtAddr {
type Output = Self;
#[inline]
fn sub(self, rhs: usize) -> Self::Output {
self - rhs as u64
}
}

#[cfg(target_pointer_width = "64")]
impl SubAssign<usize> for VirtAddr {
#[inline]
fn sub_assign(&mut self, rhs: usize) {
self.sub_assign(rhs as u64)
}
}

impl Sub<VirtAddr> for VirtAddr {
type Output = u64;
#[inline]
Expand Down Expand Up @@ -564,23 +530,6 @@ impl AddAssign<u64> for PhysAddr {
}
}

#[cfg(target_pointer_width = "64")]
impl Add<usize> for PhysAddr {
type Output = Self;
#[inline]
fn add(self, rhs: usize) -> Self::Output {
self + rhs as u64
}
}

#[cfg(target_pointer_width = "64")]
impl AddAssign<usize> for PhysAddr {
#[inline]
fn add_assign(&mut self, rhs: usize) {
self.add_assign(rhs as u64)
}
}

impl Sub<u64> for PhysAddr {
type Output = Self;
#[inline]
Expand All @@ -596,23 +545,6 @@ impl SubAssign<u64> for PhysAddr {
}
}

#[cfg(target_pointer_width = "64")]
impl Sub<usize> for PhysAddr {
type Output = Self;
#[inline]
fn sub(self, rhs: usize) -> Self::Output {
self - rhs as u64
}
}

#[cfg(target_pointer_width = "64")]
impl SubAssign<usize> for PhysAddr {
#[inline]
fn sub_assign(&mut self, rhs: usize) {
self.sub_assign(rhs as u64)
}
}

impl Sub<PhysAddr> for PhysAddr {
type Output = u64;
#[inline]
Expand Down

0 comments on commit 5bbc76e

Please sign in to comment.