Skip to content

Commit

Permalink
lint: clippy::transmute_ptr_to_ptr lint violations
Browse files Browse the repository at this point in the history
This is a pedantic lint, but it removes a transmute where a cast will do.
The code is safe for the same reasons the transmute is safe: `BStr` is a repr
transparent wrapper around `[u8]`.
  • Loading branch information
lopopolo authored and BurntSushi committed Nov 13, 2024
1 parent 46afa00 commit ef95d88
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/bstr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::mem;

#[cfg(feature = "alloc")]
use alloc::boxed::Box;

Expand Down Expand Up @@ -72,12 +70,12 @@ impl BStr {

#[inline]
pub(crate) fn from_bytes(slice: &[u8]) -> &BStr {
unsafe { mem::transmute(slice) }
unsafe { &*(slice as *const [u8] as *const BStr) }
}

#[inline]
pub(crate) fn from_bytes_mut(slice: &mut [u8]) -> &mut BStr {
unsafe { mem::transmute(slice) }
unsafe { &mut *(slice as *mut [u8] as *mut BStr) }
}

#[inline]
Expand Down

0 comments on commit ef95d88

Please sign in to comment.