Skip to content

Commit d59e9ae

Browse files
committed
style(lib): Address clippy panics and missing_panics_doc lints
1 parent 83da75a commit d59e9ae

9 files changed

Lines changed: 23 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ map_err_ignore = "allow"
130130
map_unwrap_or = "allow"
131131
match_wild_err_arm = "allow"
132132
missing_fields_in_debug = "allow" # TODO: use finish_non_exhaustive
133-
missing_panics_doc = "allow" # TODO: might be false
134133
multiple_inherent_impl = "allow"
135134
multiple_unsafe_ops_per_block = "allow"
136135
needless_pass_by_value = "allow"
137-
panic = "allow"
138136
pattern_type_mismatch = "allow"
139137
redundant_closure_for_method_calls = "allow"
140138
redundant_else = "allow"

src/client/conn/http1.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ where
101101
/// # Errors
102102
///
103103
/// Returns an error if the connection encounters an error while being polled to completion.
104+
#[allow(clippy::missing_panics_doc, reason="panic behavior consistent with future's existing invariant")]
104105
pub async fn without_shutdown(self) -> crate::Result<Parts<T>> {
105106
let mut conn = Some(self);
106107
crate::common::future::poll_fn(move |cx| -> Poll<crate::Result<Parts<T>>> {
@@ -237,7 +238,7 @@ where
237238
Ok(Ok(resp)) => Ok(resp),
238239
Ok(Err(err)) => Err(err),
239240
// this is definite bug if it happens, but it shouldn't happen!
240-
Err(_canceled) => panic!("dispatch dropped without returning error"),
241+
Err(_canceled) => unreachable!("dispatch dropped without returning error"),
241242
},
242243
Err(_req) => {
243244
debug!("connection was not ready");
@@ -267,7 +268,7 @@ where
267268
Ok(Ok(res)) => Ok(res),
268269
Ok(Err(err)) => Err(err),
269270
// this is definite bug if it happens, but it shouldn't happen!
270-
Err(_) => panic!("dispatch dropped without returning error"),
271+
Err(_) => unreachable!("dispatch dropped without returning error"),
271272
},
272273
Err(req) => {
273274
debug!("connection was not ready");

src/client/conn/http2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
Ok(Ok(resp)) => Ok(resp),
171171
Ok(Err(err)) => Err(err),
172172
// this is definite bug if it happens, but it shouldn't happen!
173-
Err(_canceled) => panic!("dispatch dropped without returning error"),
173+
Err(_canceled) => unreachable!("dispatch dropped without returning error"),
174174
},
175175
Err(_req) => {
176176
debug!("connection was not ready");
@@ -201,7 +201,7 @@ where
201201
Ok(Ok(res)) => Ok(res),
202202
Ok(Err(err)) => Err(err),
203203
// this is definite bug if it happens, but it shouldn't happen!
204-
Err(_) => panic!("dispatch dropped without returning error"),
204+
Err(_) => unreachable!("dispatch dropped without returning error"),
205205
},
206206
Err(req) => {
207207
debug!("connection was not ready");

src/common/lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub(crate) trait LockResultExt<T> {
44
fn panic_if_poisoned(self) -> T;
55
}
66

7+
#[allow(clippy::panic)]
78
impl<T> LockResultExt<T> for LockResult<T> {
89
#[track_caller]
910
fn panic_if_poisoned(self) -> T {

src/common/time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl Time {
3333
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
3434
pub(crate) fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
3535
match &self {
36+
#[allow(clippy::panic, reason="Reachable only through user misconfiguration")]
3637
Time::Empty => {
3738
panic!("You must supply a timer.")
3839
}
@@ -43,6 +44,7 @@ impl Time {
4344
#[cfg(all(feature = "server", feature = "http1"))]
4445
pub(crate) fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
4546
match &self {
47+
#[allow(clippy::panic, reason="Reachable only through user misconfiguration")]
4648
Time::Empty => {
4749
panic!("You must supply a timer.")
4850
}
@@ -59,6 +61,7 @@ impl Time {
5961

6062
pub(crate) fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
6163
match &self {
64+
#[allow(clippy::panic, reason="Only reachable through internal invariant failure, our state can't be trusted")]
6265
Time::Empty => {
6366
panic!("You must supply a timer.")
6467
}
@@ -77,6 +80,7 @@ impl Time {
7780
Time::Timer(..) => Some(dur),
7881
},
7982
Dur::Configured(Some(dur)) => match self {
83+
#[allow(clippy::panic, reason="Reachable only through user misconfiguration.")]
8084
Time::Empty => panic!("timeout `{name}` set, but no timer set",),
8185
Time::Timer(..) => Some(dur),
8286
},

src/ext/h1_reason_phrase.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ impl ReasonPhrase {
4040
}
4141

4242
/// Converts a static byte slice to a reason phrase.
43+
///
44+
/// # Panics
45+
///
46+
/// This method will panic if 'reason' contains an invalid byte. In a const context,
47+
/// this is a compile-time error instead.
4348
pub const fn from_static(reason: &'static [u8]) -> Self {
44-
// TODO: this can be made const once MSRV is >= 1.57.0
4549
assert!(
4650
find_invalid_byte(reason).is_none(),
4751
"invalid byte in static reason phrase"

src/proto/h1/role.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ impl Http1Transaction for Server {
433433
debug!("response with HTTP2 version coerced to HTTP/1.1");
434434
extend(dst, b"HTTP/1.1 ");
435435
}
436+
#[allow(clippy::panic, reason="Only reachable if the caller sets an usnupported version on the request.")]
436437
other => panic!("unexpected response version: {other:?}"),
437438
}
438439

@@ -1221,6 +1222,7 @@ impl Http1Transaction for Client {
12211222
debug!("request with HTTP2 version coerced to HTTP/1.1");
12221223
extend(dst, b"HTTP/1.1");
12231224
}
1225+
#[allow(clippy::panic, reason="Only reachable if the caller sets an usnupported version on the request.")]
12241226
other => panic!("unexpected request version: {other:?}"),
12251227
}
12261228
extend(dst, b"\r\n");

src/rt/io.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ impl ReadBufCursor<'_> {
337337
/// # Safety
338338
///
339339
/// The caller must take care that `n` more bytes have been initialized.
340+
///
341+
/// # Panics
342+
///
343+
/// This method will panic if advancing would cause the filled cursor to
344+
/// overflow `usize`.
340345
#[inline]
341346
pub unsafe fn advance(&mut self, n: usize) {
342347
self.buf.filled = self.buf.filled.checked_add(n).expect("overflow");

src/server/conn/http1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ where
178178
/// # Error
179179
///
180180
/// This errors if the underlying connection protocol is not HTTP/1.
181+
#[allow(clippy::missing_panics_doc, reason="All futures share similar panic behavior when polled after completion")]
181182
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>> {
182183
let mut zelf = Some(self);
183184
crate::common::future::poll_fn(move |cx| {

0 commit comments

Comments
 (0)