gimli-rs / gimli

A library for reading and writing the DWARF debugging format
https://docs.rs/gimli/
Apache License 2.0
831 stars 105 forks source link

Fix some clippy warnings #692

Closed Enselic closed 7 months ago

Enselic commented 7 months ago

This PR makes these commands return no warnings (except "unknown lint" from 1.60 for clippy::bool_to_int_with_if and clippy::derive_partial_eq_without_eq).

cargo +1.75 clippy --lib    # current stable version
cargo +1.65 clippy --lib
cargo +1.60 clippy --lib --no-default-features --features read

In the case of #![allow(clippy::unnecessary_cast)] the current code is by my estimation clearer and more symmetric than the code clippy would want, so I ended up allowing unnecessary casts.

philipc commented 7 months ago

In the case of #![allow(clippy::unnecessary_cast)] the current code is by my estimation clearer and more symmetric than the code clippy would want, so I ended up allowing unnecessary casts.

Do you mean these changes? They seem okay to me at first glance.

diff --git a/src/read/endian_reader.rs b/src/read/endian_reader.rs
index 8852b380..ef927e52 100644
--- a/src/read/endian_reader.rs
+++ b/src/read/endian_reader.rs
@@ -393,8 +393,8 @@ where

     #[inline]
     fn offset_from(&self, base: &EndianReader<Endian, T>) -> usize {
-        let base_ptr = base.bytes().as_ptr() as *const u8 as usize;
-        let ptr = self.bytes().as_ptr() as *const u8 as usize;
+        let base_ptr = base.bytes().as_ptr() as usize;
+        let ptr = self.bytes().as_ptr() as usize;
         debug_assert!(base_ptr <= ptr);
         debug_assert!(ptr + self.bytes().len() <= base_ptr + base.bytes().len());
         ptr - base_ptr
diff --git a/src/read/endian_slice.rs b/src/read/endian_slice.rs
index 0db28dac..b327a84f 100644
--- a/src/read/endian_slice.rs
+++ b/src/read/endian_slice.rs
@@ -68,8 +68,8 @@ where
     /// of the given slice.
     #[inline]
     pub fn offset_from(&self, base: EndianSlice<'input, Endian>) -> usize {
-        let base_ptr = base.slice.as_ptr() as *const u8 as usize;
-        let ptr = self.slice.as_ptr() as *const u8 as usize;
+        let base_ptr = base.slice.as_ptr() as usize;
+        let ptr = self.slice.as_ptr() as usize;
         debug_assert!(base_ptr <= ptr);
         debug_assert!(ptr + self.slice.len() <= base_ptr + base.slice.len());
         ptr - base_ptr
Enselic commented 7 months ago

Do you mean these changes? They seem okay to me at first glance.

Ok, let's go with those then. I pushed a commit for that now.