diff --git a/Cargo.toml b/Cargo.toml index f5446c6629..1c2b1c021b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,11 +130,9 @@ map_err_ignore = "allow" map_unwrap_or = "allow" match_wild_err_arm = "allow" missing_fields_in_debug = "allow" # TODO: use finish_non_exhaustive -missing_panics_doc = "allow" # TODO: might be false multiple_inherent_impl = "allow" multiple_unsafe_ops_per_block = "allow" needless_pass_by_value = "allow" -panic = "allow" pattern_type_mismatch = "allow" redundant_closure_for_method_calls = "allow" redundant_else = "allow" diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index bdb03171d4..859be4abae 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -101,6 +101,7 @@ where /// # Errors /// /// Returns an error if the connection encounters an error while being polled to completion. + #[allow(clippy::missing_panics_doc, reason="panic behavior consistent with future's existing invariant")] pub async fn without_shutdown(self) -> crate::Result> { let mut conn = Some(self); crate::common::future::poll_fn(move |cx| -> Poll>> { @@ -237,7 +238,7 @@ where Ok(Ok(resp)) => Ok(resp), Ok(Err(err)) => Err(err), // this is definite bug if it happens, but it shouldn't happen! - Err(_canceled) => panic!("dispatch dropped without returning error"), + Err(_canceled) => unreachable!("dispatch dropped without returning error"), }, Err(_req) => { debug!("connection was not ready"); @@ -267,7 +268,7 @@ where Ok(Ok(res)) => Ok(res), Ok(Err(err)) => Err(err), // this is definite bug if it happens, but it shouldn't happen! - Err(_) => panic!("dispatch dropped without returning error"), + Err(_) => unreachable!("dispatch dropped without returning error"), }, Err(req) => { debug!("connection was not ready"); diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index 10613b354a..4df19a10cc 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -170,7 +170,7 @@ where Ok(Ok(resp)) => Ok(resp), Ok(Err(err)) => Err(err), // this is definite bug if it happens, but it shouldn't happen! - Err(_canceled) => panic!("dispatch dropped without returning error"), + Err(_canceled) => unreachable!("dispatch dropped without returning error"), }, Err(_req) => { debug!("connection was not ready"); @@ -201,7 +201,7 @@ where Ok(Ok(res)) => Ok(res), Ok(Err(err)) => Err(err), // this is definite bug if it happens, but it shouldn't happen! - Err(_) => panic!("dispatch dropped without returning error"), + Err(_) => unreachable!("dispatch dropped without returning error"), }, Err(req) => { debug!("connection was not ready"); diff --git a/src/common/lock.rs b/src/common/lock.rs index 4e2b70bff2..24b5d104f1 100644 --- a/src/common/lock.rs +++ b/src/common/lock.rs @@ -4,6 +4,7 @@ pub(crate) trait LockResultExt { fn panic_if_poisoned(self) -> T; } +#[allow(clippy::panic)] impl LockResultExt for LockResult { #[track_caller] fn panic_if_poisoned(self) -> T { diff --git a/src/common/time.rs b/src/common/time.rs index b3534f1580..2ada2163f1 100644 --- a/src/common/time.rs +++ b/src/common/time.rs @@ -33,6 +33,7 @@ impl Time { #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] pub(crate) fn sleep(&self, duration: Duration) -> Pin> { match &self { + #[allow(clippy::panic, reason = "Reachable only through user misconfiguration")] Time::Empty => { panic!("You must supply a timer.") } @@ -43,6 +44,7 @@ impl Time { #[cfg(all(feature = "server", feature = "http1"))] pub(crate) fn sleep_until(&self, deadline: Instant) -> Pin> { match &self { + #[allow(clippy::panic, reason = "Reachable only through user misconfiguration")] Time::Empty => { panic!("You must supply a timer.") } @@ -59,6 +61,7 @@ impl Time { pub(crate) fn reset(&self, sleep: &mut Pin>, new_deadline: Instant) { match &self { + #[allow(clippy::panic, reason = "Reachable only through user misconfiguration")] Time::Empty => { panic!("You must supply a timer.") } @@ -77,6 +80,10 @@ impl Time { Time::Timer(..) => Some(dur), }, Dur::Configured(Some(dur)) => match self { + #[allow( + clippy::panic, + reason = "Reachable only through user misconfiguration." + )] Time::Empty => panic!("timeout `{name}` set, but no timer set",), Time::Timer(..) => Some(dur), }, diff --git a/src/ext/h1_reason_phrase.rs b/src/ext/h1_reason_phrase.rs index c4c615bc20..3ebdfcf9a9 100644 --- a/src/ext/h1_reason_phrase.rs +++ b/src/ext/h1_reason_phrase.rs @@ -40,8 +40,12 @@ impl ReasonPhrase { } /// Converts a static byte slice to a reason phrase. + /// + /// # Panics + /// + /// This method will panic if 'reason' contains an invalid byte. In a const context, + /// this is a compile-time error instead. pub const fn from_static(reason: &'static [u8]) -> Self { - // TODO: this can be made const once MSRV is >= 1.57.0 assert!( find_invalid_byte(reason).is_none(), "invalid byte in static reason phrase" diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index d083d2a912..254f458f38 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -433,6 +433,7 @@ impl Http1Transaction for Server { debug!("response with HTTP2 version coerced to HTTP/1.1"); extend(dst, b"HTTP/1.1 "); } + #[allow(clippy::panic, reason="Only reachable if the caller sets an usnupported version on the request.")] other => panic!("unexpected response version: {other:?}"), } @@ -1221,6 +1222,7 @@ impl Http1Transaction for Client { debug!("request with HTTP2 version coerced to HTTP/1.1"); extend(dst, b"HTTP/1.1"); } + #[allow(clippy::panic, reason="Only reachable if the caller sets an usnupported version on the request.")] other => panic!("unexpected request version: {other:?}"), } extend(dst, b"\r\n"); diff --git a/src/rt/io.rs b/src/rt/io.rs index 9e633e69e8..31e699d73a 100644 --- a/src/rt/io.rs +++ b/src/rt/io.rs @@ -337,6 +337,11 @@ impl ReadBufCursor<'_> { /// # Safety /// /// The caller must take care that `n` more bytes have been initialized. + /// + /// # Panics + /// + /// This method will panic if advancing would cause the filled cursor to + /// overflow `usize`. #[inline] pub unsafe fn advance(&mut self, n: usize) { self.buf.filled = self.buf.filled.checked_add(n).expect("overflow"); diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index 7bd3d72e2f..bc7ab01ac5 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -178,6 +178,7 @@ where /// # Error /// /// This errors if the underlying connection protocol is not HTTP/1. + #[allow(clippy::missing_panics_doc, reason="All futures share similar panic behavior when polled after completion")] pub fn without_shutdown(self) -> impl Future>> { let mut zelf = Some(self); crate::common::future::poll_fn(move |cx| {