Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
polazarus committed Feb 10, 2025
1 parent 952423e commit e97cc73
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 25 deletions.
18 changes: 7 additions & 11 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,12 @@ where
SplitMut::Inline(inline) => inline.as_mut_ptr(),
SplitMut::Allocated(heap) => unsafe { heap.as_mut_ptr_unchecked() },
SplitMut::Borrowed(_) => {
#[cfg(debug_assertions)]
{
if cfg!(debug_assertions) {
panic!("mutable pointer of borrowed string");
}
#[cfg(not(debug_assertions))]
{
unreachable_unchecked()
} else {
unsafe {
unreachable_unchecked();
}
}
}
}
Expand Down Expand Up @@ -359,12 +358,9 @@ where
SplitMut::Inline(inline) => inline.as_mut_slice(),
SplitMut::Allocated(allocated) => unsafe { allocated.as_mut_slice_unchecked() },
SplitMut::Borrowed(_) => {
#[cfg(debug_assertions)]
{
if cfg!(debug_assertions) {
panic!("mutable slice of borrowed string");
}
#[cfg(not(debug_assertions))]
{
} else {
unsafe { unreachable_unchecked() }
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/bytes/borsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use crate::Backend;
#[cfg(test)]
mod tests;

impl<'borrow, B: Backend> BorshDeserialize for HipByt<'borrow, B> {
impl<B: Backend> BorshDeserialize for HipByt<'_, B> {
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
let len = u32::deserialize_reader(reader)? as usize;
if len == 0 {
Ok(Self::new())
} else {
let mut result = Self::with_capacity(len);
let slice = result.spare_capacity_mut();
for i in 0..len {
slice[i].write(u8::deserialize_reader(reader)?);
for byte in slice.iter_mut().take(len) {
byte.write(u8::deserialize_reader(reader)?);
}
unsafe {
result.set_len(len);
Expand All @@ -28,7 +28,7 @@ impl<'borrow, B: Backend> BorshDeserialize for HipByt<'borrow, B> {
}
}

impl<'borrow, B: Backend> BorshSerialize for HipByt<'borrow, B> {
impl<B: Backend> BorshSerialize for HipByt<'_, B> {
fn serialize<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
self.as_slice().serialize(writer)
}
Expand Down
2 changes: 1 addition & 1 deletion src/bytes/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl<'borrow, B: Backend> HipByt<'borrow, B> {
///
/// Returns `None` if this byte string is not allocated.
#[inline]
pub(super) fn take_allocated(&mut self) -> Option<Allocated<B>> {
pub(super) const fn take_allocated(&mut self) -> Option<Allocated<B>> {
match self.split() {
Split::Allocated(&allocated) => {
// Takes a copy of allocated
Expand Down
2 changes: 1 addition & 1 deletion src/bytes/raw/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::TAG_BORROWED;
#[cfg(test)]
mod tests;

const TAG_NZ: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(TAG_BORROWED) };
const TAG_NZ: NonZeroU8 = NonZeroU8::new(TAG_BORROWED).unwrap();

/// Borrowed slice representation.
///
Expand Down
4 changes: 2 additions & 2 deletions src/smart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ where
///
/// Any caller should check the uniqueness first with [`Self::is_unique`].
#[inline]
pub unsafe fn as_mut_unchecked(&mut self) -> &mut T {
pub const unsafe fn as_mut_unchecked(&mut self) -> &mut T {
// SAFETY: uniqueness precondition
unsafe { &mut self.0.as_mut().value }
}
Expand All @@ -281,7 +281,7 @@ where
/// - Any caller should check the uniqueness first with [`Self::is_unique`].
/// - The referenced value must outlive `'a`.
#[inline]
pub(crate) unsafe fn as_mut_unchecked_extended<'a>(&mut self) -> &'a mut T
pub(crate) const unsafe fn as_mut_unchecked_extended<'a>(&mut self) -> &'a mut T
where
Self: 'a,
{
Expand Down
4 changes: 2 additions & 2 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ where
/// [`from_utf8_unchecked`]: HipStr::from_utf8_unchecked
/// [`into_bytes`]: HipStr::into_bytes
#[inline]
pub fn from_utf8(bytes: HipByt<'borrow, B>) -> Result<Self, FromUtf8Error<'borrow, B>> {
match core::str::from_utf8(&bytes) {
pub const fn from_utf8(bytes: HipByt<'borrow, B>) -> Result<Self, FromUtf8Error<'borrow, B>> {
match core::str::from_utf8(bytes.as_slice()) {
Ok(_) => {
// SAFETY: checked above
Ok(unsafe { Self::from_utf8_unchecked(bytes) })
Expand Down
6 changes: 3 additions & 3 deletions src/string/borsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ use crate::Backend;
#[cfg(test)]
mod tests;

impl<'borrow, B: Backend> BorshDeserialize for HipStr<'borrow, B> {
impl<B: Backend> BorshDeserialize for HipStr<'_, B> {
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
let bytes: HipByt<'borrow, B> = HipByt::deserialize_reader(reader)?;
let bytes: HipByt<B> = HipByt::deserialize_reader(reader)?;
Self::try_from(bytes).map_err(|err| {
let msg = err.to_string();
Error::new(ErrorKind::InvalidData, msg)
})
}
}

impl<'borrow, B: Backend> BorshSerialize for HipStr<'borrow, B> {
impl<B: Backend> BorshSerialize for HipStr<'_, B> {
fn serialize<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
self.as_bytes().serialize(writer)
}
Expand Down
2 changes: 1 addition & 1 deletion src/string/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ symmetric_ord! {
[B] [where B: Backend] (&BString, HipStr<'_, B>) = bstr_cmp;
}

impl<'a, B> TryFrom<BString> for HipStr<'a, B>
impl<B> TryFrom<BString> for HipStr<'_, B>
where
B: Backend,
{
Expand Down

0 comments on commit e97cc73

Please sign in to comment.