From ccbd7a220ad844a5f90cd23f4a35f7202df53cdc Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Mon, 28 Mar 2022 00:50:37 -0700 Subject: [PATCH] Remove usize trait impls 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 https://github.com/rust-osdev/x86_64/issues/293#issuecomment-901804330 Signed-off-by: Joe Richey --- src/addr.rs | 68 ----------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/src/addr.rs b/src/addr.rs index 09ec65328..46852c081 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -281,23 +281,6 @@ impl AddAssign for VirtAddr { } } -#[cfg(target_pointer_width = "64")] -impl Add for VirtAddr { - type Output = Self; - #[inline] - fn add(self, rhs: usize) -> Self::Output { - self + rhs as u64 - } -} - -#[cfg(target_pointer_width = "64")] -impl AddAssign for VirtAddr { - #[inline] - fn add_assign(&mut self, rhs: usize) { - self.add_assign(rhs as u64) - } -} - impl Sub for VirtAddr { type Output = Self; #[inline] @@ -313,23 +296,6 @@ impl SubAssign for VirtAddr { } } -#[cfg(target_pointer_width = "64")] -impl Sub for VirtAddr { - type Output = Self; - #[inline] - fn sub(self, rhs: usize) -> Self::Output { - self - rhs as u64 - } -} - -#[cfg(target_pointer_width = "64")] -impl SubAssign for VirtAddr { - #[inline] - fn sub_assign(&mut self, rhs: usize) { - self.sub_assign(rhs as u64) - } -} - impl Sub for VirtAddr { type Output = u64; #[inline] @@ -564,23 +530,6 @@ impl AddAssign for PhysAddr { } } -#[cfg(target_pointer_width = "64")] -impl Add for PhysAddr { - type Output = Self; - #[inline] - fn add(self, rhs: usize) -> Self::Output { - self + rhs as u64 - } -} - -#[cfg(target_pointer_width = "64")] -impl AddAssign for PhysAddr { - #[inline] - fn add_assign(&mut self, rhs: usize) { - self.add_assign(rhs as u64) - } -} - impl Sub for PhysAddr { type Output = Self; #[inline] @@ -596,23 +545,6 @@ impl SubAssign for PhysAddr { } } -#[cfg(target_pointer_width = "64")] -impl Sub for PhysAddr { - type Output = Self; - #[inline] - fn sub(self, rhs: usize) -> Self::Output { - self - rhs as u64 - } -} - -#[cfg(target_pointer_width = "64")] -impl SubAssign for PhysAddr { - #[inline] - fn sub_assign(&mut self, rhs: usize) { - self.sub_assign(rhs as u64) - } -} - impl Sub for PhysAddr { type Output = u64; #[inline]