Skip to content

Commit 885dacb

Browse files
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 #202).
1 parent 7e80f7d commit 885dacb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/lib.rs

+3-4
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,
@@ -1415,10 +1416,7 @@ pub unsafe trait AsBytes {
14151416
#[inline]
14161417
fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()> {
14171418
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());
1419+
bytes.get_mut(start..)?.copy_from_slice(self.as_bytes());
14221420
Some(())
14231421
}
14241422
}
@@ -2193,6 +2191,7 @@ where
21932191
/// `new_slice` panics if `T` is a zero-sized type.
21942192
#[inline]
21952193
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
2194+
#[allow(clippy::expect_used)]
21962195
let remainder = bytes
21972196
.len()
21982197
.checked_rem(mem::size_of::<T>())

0 commit comments

Comments
 (0)