Skip to content

Commit cd6af66

Browse files
authored
refactor(lib): resolve unused warning (#3344)
In CI, check unused_imports and dead_code
1 parent f86c4b5 commit cd6af66

File tree

21 files changed

+199
-91
lines changed

21 files changed

+199
-91
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ jobs:
146146

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

150152
ffi:
151153
name: Test C API (FFI)

src/body/length.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl DecodedLength {
3333
/// Should only be called if previously confirmed this isn't
3434
/// CLOSE_DELIMITED or CHUNKED.
3535
#[inline]
36-
#[cfg(feature = "http1")]
36+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
3737
pub(crate) fn danger_len(self) -> u64 {
3838
debug_assert!(self.0 < Self::CHUNKED.0);
3939
self.0
@@ -72,7 +72,7 @@ impl DecodedLength {
7272
/// This includes 0, which of course is an exact known length.
7373
///
7474
/// It would return false if "chunked" or otherwise size-unknown.
75-
#[cfg(feature = "http2")]
75+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
7676
pub(crate) fn is_exact(&self) -> bool {
7777
self.0 <= MAX_LEN
7878
}

src/body/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use http_body::SizeHint;
2626

2727
pub use self::incoming::Incoming;
2828

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

src/client/dispatch.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#[cfg(feature = "http2")]
22
use std::future::Future;
33

4+
#[cfg(feature = "http2")]
45
use http::{Request, Response};
6+
#[cfg(feature = "http2")]
57
use http_body::Body;
8+
#[cfg(feature = "http2")]
69
use pin_project_lite::pin_project;
710
use tokio::sync::{mpsc, oneshot};
811

9-
use crate::{
10-
body::Incoming,
11-
common::{task, Poll},
12-
};
12+
use crate::common::{task, Poll};
1313
#[cfg(feature = "http2")]
14-
use crate::{common::Pin, proto::h2::client::ResponseFutMap};
14+
use crate::{body::Incoming, common::Pin, proto::h2::client::ResponseFutMap};
1515

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

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

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

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

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

107+
#[cfg(feature = "http1")]
101108
pub(crate) fn send(&mut self, val: T) -> Result<Promise<U>, T> {
102109
if !self.can_send() {
103110
return Err(val);

src/common/buf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ impl<T: Buf> BufList<T> {
2121
}
2222

2323
#[inline]
24-
#[cfg(feature = "http1")]
2524
pub(crate) fn bufs_cnt(&self) -> usize {
2625
self.bufs.len()
2726
}

src/common/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#[cfg(any(feature = "http2", test))]
1+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
22
mod compat;
33
mod rewind;
44

5-
#[cfg(any(feature = "http2", test))]
5+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
66
pub(crate) use self::compat::{compat, Compat};
77
pub(crate) use self::rewind::Rewind;

src/common/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ macro_rules! ready {
77
};
88
}
99

10+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
1011
pub(crate) mod buf;
1112
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
1213
pub(crate) mod date;
1314
#[cfg(not(feature = "http2"))]
1415
pub(crate) mod exec;
1516
pub(crate) mod io;
1617
pub(crate) mod task;
17-
#[cfg(any(feature = "http1", feature = "http2", feature = "server"))]
18+
#[cfg(any(
19+
all(feature = "server", feature = "http1"),
20+
all(any(feature = "client", feature = "server"), feature = "http2"),
21+
))]
1822
pub(crate) mod time;
1923
pub(crate) mod watch;
2024

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

2327
// group up types normally needed for `Future`
24-
cfg_proto! {
25-
pub(crate) use std::marker::Unpin;
26-
}
2728
pub(crate) use std::{future::Future, pin::Pin};

src/common/task.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
#[cfg(feature = "http1")]
2-
use std::convert::Infallible;
31
pub(crate) use std::task::{Context, Poll};
42

53
/// A function to help "yield" a future, such that it is re-scheduled immediately.
64
///
75
/// Useful for spin counts, so a future doesn't hog too much time.
8-
#[cfg(feature = "http1")]
9-
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Infallible> {
6+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
7+
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<std::convert::Infallible> {
108
cx.waker().wake_by_ref();
119
Poll::Pending
1210
}

src/common/time.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
2+
use std::time::Duration;
13
use std::{fmt, sync::Arc};
2-
use std::{
3-
pin::Pin,
4-
time::{Duration, Instant},
5-
};
4+
use std::{pin::Pin, time::Instant};
65

76
use crate::rt::Sleep;
87
use crate::rt::Timer;
@@ -55,6 +54,7 @@ impl<F> Future for HyperTimeout<F> where F: Future {
5554
*/
5655

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

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

0 commit comments

Comments
 (0)