Skip to content

Commit

Permalink
Enable clippy::expect_used, address warnings
Browse files Browse the repository at this point in the history
This enables Clippy's
[`expect_used`](https://rust-lang.github.io/rust-clippy/master/index.html#/expect_used)
lint, which errors on calls to `Option::expect` and `Result::{expect,
expect_err}`. The intent of enabling this lint is to reduce the number
of panics emitted in `zerocopy`'s code (issue google#202).
  • Loading branch information
jrvanwhy committed Oct 24, 2023
1 parent 3ee51b2 commit e08b742
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
clippy::correctness,
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::expect_used,
clippy::get_unwrap,
clippy::indexing_slicing,
clippy::missing_inline_in_public_items,
Expand Down Expand Up @@ -1026,6 +1027,7 @@ pub unsafe trait FromZeroes {
/// * Panics if `size_of::<Self>() * len` overflows.
/// * Panics if allocation of `size_of::<Self>() * len` bytes fails.
#[cfg(feature = "alloc")]
#[allow(clippy::expect_used)]
#[inline]
fn new_box_slice_zeroed(len: usize) -> Box<[Self]>
where
Expand Down Expand Up @@ -1415,10 +1417,7 @@ pub unsafe trait AsBytes {
#[inline]
fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()> {
let start = bytes.len().checked_sub(mem::size_of_val(self))?;
bytes
.get_mut(start..)
.expect("`start` should be in-bounds of `bytes`")
.copy_from_slice(self.as_bytes());
bytes.get_mut(start..)?.copy_from_slice(self.as_bytes());
Some(())
}
}
Expand Down Expand Up @@ -2241,6 +2240,7 @@ where
/// `new_slice` panics if `T` is a zero-sized type.
#[inline]
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
#[allow(clippy::expect_used)]
let remainder = bytes
.len()
.checked_rem(mem::size_of::<T>())
Expand Down

0 comments on commit e08b742

Please sign in to comment.