Skip to content

Commit

Permalink
refactor(lib): resolve unused warning (#3344)
Browse files Browse the repository at this point in the history
In CI, check unused_imports and dead_code
  • Loading branch information
tottoto authored Oct 12, 2023
1 parent f86c4b5 commit cd6af66
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ jobs:

- name: check --feature-powerset
run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip ffi,tracing
env:
RUSTFLAGS: "-D dead_code -D unused_imports"

ffi:
name: Test C API (FFI)
Expand Down
4 changes: 2 additions & 2 deletions src/body/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl DecodedLength {
/// Should only be called if previously confirmed this isn't
/// CLOSE_DELIMITED or CHUNKED.
#[inline]
#[cfg(feature = "http1")]
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
pub(crate) fn danger_len(self) -> u64 {
debug_assert!(self.0 < Self::CHUNKED.0);
self.0
Expand Down Expand Up @@ -72,7 +72,7 @@ impl DecodedLength {
/// This includes 0, which of course is an exact known length.
///
/// It would return false if "chunked" or otherwise size-unknown.
#[cfg(feature = "http2")]
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
pub(crate) fn is_exact(&self) -> bool {
self.0 <= MAX_LEN
}
Expand Down
2 changes: 1 addition & 1 deletion src/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use http_body::SizeHint;

pub use self::incoming::Incoming;

#[cfg(feature = "http1")]
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
pub(crate) use self::incoming::Sender;
pub(crate) use self::length::DecodedLength;

Expand Down
17 changes: 12 additions & 5 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#[cfg(feature = "http2")]
use std::future::Future;

#[cfg(feature = "http2")]
use http::{Request, Response};
#[cfg(feature = "http2")]
use http_body::Body;
#[cfg(feature = "http2")]
use pin_project_lite::pin_project;
use tokio::sync::{mpsc, oneshot};

use crate::{
body::Incoming,
common::{task, Poll},
};
use crate::common::{task, Poll};
#[cfg(feature = "http2")]
use crate::{common::Pin, proto::h2::client::ResponseFutMap};
use crate::{body::Incoming, common::Pin, proto::h2::client::ResponseFutMap};

#[cfg(test)]
pub(crate) type RetryPromise<T, U> = oneshot::Receiver<Result<U, (crate::Error, Option<T>)>>;
Expand All @@ -21,6 +21,7 @@ pub(crate) fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
let (tx, rx) = mpsc::unbounded_channel();
let (giver, taker) = want::new();
let tx = Sender {
#[cfg(feature = "http1")]
buffered_once: false,
giver,
inner: tx,
Expand All @@ -37,6 +38,7 @@ pub(crate) struct Sender<T, U> {
/// One message is always allowed, even if the Receiver hasn't asked
/// for it yet. This boolean keeps track of whether we've sent one
/// without notice.
#[cfg(feature = "http1")]
buffered_once: bool,
/// The Giver helps watch that the the Receiver side has been polled
/// when the queue is empty. This helps us know when a request and
Expand All @@ -59,20 +61,24 @@ pub(crate) struct UnboundedSender<T, U> {
}

impl<T, U> Sender<T, U> {
#[cfg(feature = "http1")]
pub(crate) fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
self.giver
.poll_want(cx)
.map_err(|_| crate::Error::new_closed())
}

#[cfg(feature = "http1")]
pub(crate) fn is_ready(&self) -> bool {
self.giver.is_wanting()
}

#[cfg(feature = "http1")]
pub(crate) fn is_closed(&self) -> bool {
self.giver.is_canceled()
}

#[cfg(feature = "http1")]
fn can_send(&mut self) -> bool {
if self.giver.give() || !self.buffered_once {
// If the receiver is ready *now*, then of course we can send.
Expand All @@ -98,6 +104,7 @@ impl<T, U> Sender<T, U> {
.map_err(|mut e| (e.0).0.take().expect("envelope not dropped").0)
}

#[cfg(feature = "http1")]
pub(crate) fn send(&mut self, val: T) -> Result<Promise<U>, T> {
if !self.can_send() {
return Err(val);
Expand Down
1 change: 0 additions & 1 deletion src/common/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl<T: Buf> BufList<T> {
}

#[inline]
#[cfg(feature = "http1")]
pub(crate) fn bufs_cnt(&self) -> usize {
self.bufs.len()
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(any(feature = "http2", test))]
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
mod compat;
mod rewind;

#[cfg(any(feature = "http2", test))]
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
pub(crate) use self::compat::{compat, Compat};
pub(crate) use self::rewind::Rewind;
9 changes: 5 additions & 4 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ macro_rules! ready {
};
}

#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
pub(crate) mod buf;
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
pub(crate) mod date;
#[cfg(not(feature = "http2"))]
pub(crate) mod exec;
pub(crate) mod io;
pub(crate) mod task;
#[cfg(any(feature = "http1", feature = "http2", feature = "server"))]
#[cfg(any(
all(feature = "server", feature = "http1"),
all(any(feature = "client", feature = "server"), feature = "http2"),
))]
pub(crate) mod time;
pub(crate) mod watch;

pub(crate) use self::task::Poll;

// group up types normally needed for `Future`
cfg_proto! {
pub(crate) use std::marker::Unpin;
}
pub(crate) use std::{future::Future, pin::Pin};
6 changes: 2 additions & 4 deletions src/common/task.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#[cfg(feature = "http1")]
use std::convert::Infallible;
pub(crate) use std::task::{Context, Poll};

/// A function to help "yield" a future, such that it is re-scheduled immediately.
///
/// Useful for spin counts, so a future doesn't hog too much time.
#[cfg(feature = "http1")]
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Infallible> {
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<std::convert::Infallible> {
cx.waker().wake_by_ref();
Poll::Pending
}
9 changes: 5 additions & 4 deletions src/common/time.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
use std::time::Duration;
use std::{fmt, sync::Arc};
use std::{
pin::Pin,
time::{Duration, Instant},
};
use std::{pin::Pin, time::Instant};

use crate::rt::Sleep;
use crate::rt::Timer;
Expand Down Expand Up @@ -55,6 +54,7 @@ impl<F> Future for HyperTimeout<F> where F: Future {
*/

impl Time {
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
pub(crate) fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
match *self {
Time::Empty => {
Expand All @@ -64,6 +64,7 @@ impl Time {
}
}

#[cfg(feature = "http1")]
pub(crate) fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
match *self {
Time::Empty => {
Expand Down
Loading

0 comments on commit cd6af66

Please sign in to comment.