Skip to content

Commit e08b742

Browse files
author
Johnathan Van Why
committed
Enable clippy::expect_used, address warnings
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).
1 parent 3ee51b2 commit e08b742

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
clippy::correctness,
173173
clippy::dbg_macro,
174174
clippy::decimal_literal_representation,
175+
clippy::expect_used,
175176
clippy::get_unwrap,
176177
clippy::indexing_slicing,
177178
clippy::missing_inline_in_public_items,
@@ -1026,6 +1027,7 @@ pub unsafe trait FromZeroes {
10261027
/// * Panics if `size_of::<Self>() * len` overflows.
10271028
/// * Panics if allocation of `size_of::<Self>() * len` bytes fails.
10281029
#[cfg(feature = "alloc")]
1030+
#[allow(clippy::expect_used)]
10291031
#[inline]
10301032
fn new_box_slice_zeroed(len: usize) -> Box<[Self]>
10311033
where
@@ -1415,10 +1417,7 @@ pub unsafe trait AsBytes {
14151417
#[inline]
14161418
fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()> {
14171419
let start = bytes.len().checked_sub(mem::size_of_val(self))?;
1418-
bytes
1419-
.get_mut(start..)
1420-
.expect("`start` should be in-bounds of `bytes`")
1421-
.copy_from_slice(self.as_bytes());
1420+
bytes.get_mut(start..)?.copy_from_slice(self.as_bytes());
14221421
Some(())
14231422
}
14241423
}
@@ -2241,6 +2240,7 @@ where
22412240
/// `new_slice` panics if `T` is a zero-sized type.
22422241
#[inline]
22432242
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
2243+
#[allow(clippy::expect_used)]
22442244
let remainder = bytes
22452245
.len()
22462246
.checked_rem(mem::size_of::<T>())

0 commit comments

Comments
 (0)