Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the cast dependency. #124

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ edition = "2018"
bit_field = "0.9.0"
bitflags = "1.0.4"

[dependencies.cast]
version = "0.2.2"
default-features = false

[features]
deny-warnings = []
20 changes: 10 additions & 10 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ impl VirtAddr {

/// Creates a virtual address from the given pointer
pub fn from_ptr<T>(ptr: *const T) -> Self {
Self::new(cast::u64(ptr as usize))
Self::new(ptr as u64)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not have a #[cfg(target_pointer_width = "64")]. There are no >64-architectures right now, so this cast should never be truncating in practice, but maybe we should add the cfg attribute anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like cfg was already missing there. Adding it would technically be a breaking change.

It could also get a #[cfg(any(target_pointer_width = "32", target_pointer_width = "64")] to make it 'less breaking'. Not sure if anybody would want to use this function on 32-bit though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding #[cfg(any(target_pointer_width = "32", target_pointer_width = "64")] with a short comment that target_pointer_width = "32" is only added for reducing breakage seems like the best option to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done.


/// Converts the address to a raw pointer.
#[cfg(target_pointer_width = "64")]
pub fn as_ptr<T>(self) -> *const T {
cast::usize(self.as_u64()) as *const T
self.as_u64() as *const T
}

/// Converts the address to a mutable raw pointer.
Expand Down Expand Up @@ -181,14 +181,14 @@ impl AddAssign<u64> for VirtAddr {
impl Add<usize> for VirtAddr {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
self + cast::u64(rhs)
self + rhs as u64
}
}

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

Expand All @@ -209,14 +209,14 @@ impl SubAssign<u64> for VirtAddr {
impl Sub<usize> for VirtAddr {
type Output = Self;
fn sub(self, rhs: usize) -> Self::Output {
self - cast::u64(rhs)
self - rhs as u64
}
}

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

Expand Down Expand Up @@ -347,14 +347,14 @@ impl AddAssign<u64> for PhysAddr {
impl Add<usize> for PhysAddr {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
self + cast::u64(rhs)
self + rhs as u64
}
}

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

Expand All @@ -375,14 +375,14 @@ impl SubAssign<u64> for PhysAddr {
impl Sub<usize> for PhysAddr {
type Output = Self;
fn sub(self, rhs: usize) -> Self::Output {
self - cast::u64(rhs)
self - rhs as u64
}
}

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

Expand Down