Skip to content

Commit 9dff004

Browse files
jplatteseanmonstar
authored andcommitted
refactor(lib): Use cfg(all(...)) instead of multiple cfg attributes
1 parent 2c8121f commit 9dff004

File tree

9 files changed

+30
-52
lines changed

9 files changed

+30
-52
lines changed

src/body/body.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use super::DecodedLength;
1616
#[cfg(feature = "stream")]
1717
use crate::common::sync_wrapper::SyncWrapper;
1818
use crate::common::Future;
19-
#[cfg(any(feature = "http1", feature = "http2"))]
20-
#[cfg(feature = "client")]
19+
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
2120
use crate::common::Never;
2221
use crate::common::{task, watch, Pin, Poll};
2322
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -74,8 +73,7 @@ struct Extra {
7473
delayed_eof: Option<DelayEof>,
7574
}
7675

77-
#[cfg(any(feature = "http1", feature = "http2"))]
78-
#[cfg(feature = "client")]
76+
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
7977
type DelayEofUntil = oneshot::Receiver<Never>;
8078

8179
enum DelayEof {

src/client/conn.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ use std::fmt;
5151
#[cfg(feature = "http2")]
5252
use std::marker::PhantomData;
5353
use std::sync::Arc;
54-
#[cfg(feature = "runtime")]
55-
#[cfg(feature = "http2")]
54+
#[cfg(all(feature = "runtime", feature = "http2"))]
5655
use std::time::Duration;
5756

5857
use bytes::Bytes;
@@ -63,7 +62,10 @@ use tower_service::Service;
6362

6463
use super::dispatch;
6564
use crate::body::HttpBody;
66-
use crate::common::{task, exec::{BoxSendFuture, Exec}, Future, Pin, Poll};
65+
use crate::common::{
66+
exec::{BoxSendFuture, Exec},
67+
task, Future, Pin, Poll,
68+
};
6769
use crate::proto;
6870
use crate::rt::Executor;
6971
#[cfg(feature = "http1")]

src/client/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
pub use self::connect::HttpConnector;
5353

5454
pub mod connect;
55-
#[cfg(test)]
56-
#[cfg(feature = "runtime")]
55+
#[cfg(all(test, feature = "runtime"))]
5756
mod tests;
5857

5958
cfg_feature! {

src/common/exec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::sync::Arc;
55

66
#[cfg(feature = "server")]
77
use crate::body::{Body, HttpBody};
8-
#[cfg(feature = "http2")]
9-
#[cfg(feature = "server")]
8+
#[cfg(all(feature = "http2", feature = "server"))]
109
use crate::proto::h2::server::H2Stream;
1110
use crate::rt::Executor;
1211
#[cfg(feature = "server")]

src/common/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,22 @@ macro_rules! ready {
88
}
99

1010
pub(crate) mod buf;
11-
#[cfg(any(feature = "http1", feature = "http2"))]
12-
#[cfg(feature = "server")]
11+
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
1312
pub(crate) mod date;
14-
#[cfg(any(feature = "http1", feature = "http2"))]
15-
#[cfg(feature = "server")]
13+
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
1614
pub(crate) mod drain;
1715
#[cfg(any(feature = "http1", feature = "http2"))]
1816
pub(crate) mod exec;
1917
pub(crate) mod io;
20-
#[cfg(any(feature = "http1", feature = "http2"))]
21-
#[cfg(feature = "client")]
18+
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
2219
mod lazy;
2320
mod never;
2421
#[cfg(feature = "stream")]
2522
pub(crate) mod sync_wrapper;
2623
pub(crate) mod task;
2724
pub(crate) mod watch;
2825

29-
#[cfg(any(feature = "http1", feature = "http2"))]
30-
#[cfg(feature = "client")]
26+
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
3127
pub(crate) use self::lazy::{lazy, Started as Lazy};
3228
#[cfg(any(
3329
feature = "client",

src/headers.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
use bytes::BytesMut;
33
use http::header::CONTENT_LENGTH;
44
use http::header::{HeaderValue, ValueIter};
5-
#[cfg(feature = "http2")]
6-
#[cfg(feature = "client")]
7-
use http::Method;
85
use http::HeaderMap;
6+
#[cfg(all(feature = "http2", feature = "client"))]
7+
use http::Method;
98

109
#[cfg(feature = "http1")]
1110
pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool {
@@ -29,8 +28,7 @@ fn connection_has(value: &HeaderValue, needle: &str) -> bool {
2928
false
3029
}
3130

32-
#[cfg(feature = "http1")]
33-
#[cfg(feature = "server")]
31+
#[cfg(all(feature = "http1", feature = "server"))]
3432
pub(super) fn content_length_parse(value: &HeaderValue) -> Option<u64> {
3533
value.to_str().ok().and_then(|s| s.parse().ok())
3634
}
@@ -66,8 +64,7 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
6664
}
6765
}
6866

69-
#[cfg(feature = "http2")]
70-
#[cfg(feature = "client")]
67+
#[cfg(all(feature = "http2", feature = "client"))]
7168
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
7269
match *method {
7370
Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false,

src/proto/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ pub(crate) type RequestHead = MessageHead<RequestLine>;
3737
pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri);
3838

3939
/// An incoming response message.
40-
#[cfg(feature = "http1")]
41-
#[cfg(feature = "client")]
40+
#[cfg(all(feature = "http1", feature = "client"))]
4241
pub(crate) type ResponseHead = MessageHead<http::StatusCode>;
4342

4443
#[derive(Debug)]

src/server/conn.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ use std::fmt;
4949
use std::marker::PhantomData;
5050
#[cfg(feature = "tcp")]
5151
use std::net::SocketAddr;
52-
#[cfg(feature = "runtime")]
53-
#[cfg(feature = "http2")]
52+
#[cfg(all(feature = "runtime", feature = "http2"))]
5453
use std::time::Duration;
5554

5655
use bytes::Bytes;
@@ -63,8 +62,7 @@ use crate::common::exec::{ConnStreamExec, Exec, NewSvcExec};
6362
#[cfg(feature = "http2")]
6463
use crate::common::io::Rewind;
6564
use crate::common::{task, Future, Pin, Poll, Unpin};
66-
#[cfg(feature = "http1")]
67-
#[cfg(feature = "http2")]
65+
#[cfg(all(feature = "http1", feature = "http2"))]
6866
use crate::error::{Kind, Parse};
6967
use crate::proto;
7068
use crate::service::{HttpService, MakeServiceRef};
@@ -107,8 +105,7 @@ enum ConnectionMode {
107105
#[cfg(feature = "http2")]
108106
H2Only,
109107
/// Use HTTP/1 and try to upgrade to h2 when a parse error occurs.
110-
#[cfg(feature = "http1")]
111-
#[cfg(feature = "http2")]
108+
#[cfg(all(feature = "http1", feature = "http2"))]
112109
Fallback,
113110
}
114111

@@ -160,8 +157,7 @@ where
160157
S: HttpService<Body>,
161158
{
162159
pub(super) conn: Option<ProtoServer<T, S::ResBody, S, E>>,
163-
#[cfg(feature = "http1")]
164-
#[cfg(feature = "http2")]
160+
#[cfg(all(feature = "http1", feature = "http2"))]
165161
fallback: Fallback<E>,
166162
}
167163

@@ -186,16 +182,14 @@ where
186182
H2(#[pin] proto::h2::Server<Rewind<T>, S, B, E>),
187183
}
188184

189-
#[cfg(feature = "http1")]
190-
#[cfg(feature = "http2")]
185+
#[cfg(all(feature = "http1", feature = "http2"))]
191186
#[derive(Clone, Debug)]
192187
enum Fallback<E> {
193188
ToHttp2(proto::h2::server::Config, E),
194189
Http1Only,
195190
}
196191

197-
#[cfg(feature = "http1")]
198-
#[cfg(feature = "http2")]
192+
#[cfg(all(feature = "http1", feature = "http2"))]
199193
impl<E> Fallback<E> {
200194
fn to_h2(&self) -> bool {
201195
match *self {
@@ -205,8 +199,7 @@ impl<E> Fallback<E> {
205199
}
206200
}
207201

208-
#[cfg(feature = "http1")]
209-
#[cfg(feature = "http2")]
202+
#[cfg(all(feature = "http1", feature = "http2"))]
210203
impl<E> Unpin for Fallback<E> {}
211204

212205
/// Deconstructed parts of a `Connection`.
@@ -701,8 +694,7 @@ where
701694
})
702695
}
703696

704-
#[cfg(feature = "http1")]
705-
#[cfg(feature = "http2")]
697+
#[cfg(all(feature = "http1", feature = "http2"))]
706698
fn upgrade_h2(&mut self) {
707699
trace!("Trying to upgrade connection to h2");
708700
let conn = self.conn.take();

src/service/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,16 @@ pub use tower_service::Service;
3939

4040
mod http;
4141
mod make;
42-
#[cfg(any(feature = "http1", feature = "http2"))]
43-
#[cfg(feature = "client")]
42+
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
4443
mod oneshot;
4544
mod util;
4645

4746
pub(super) use self::http::HttpService;
48-
#[cfg(any(feature = "http1", feature = "http2"))]
49-
#[cfg(feature = "client")]
47+
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
5048
pub(super) use self::make::MakeConnection;
51-
#[cfg(any(feature = "http1", feature = "http2"))]
52-
#[cfg(feature = "server")]
49+
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "server"))]
5350
pub(super) use self::make::MakeServiceRef;
54-
#[cfg(any(feature = "http1", feature = "http2"))]
55-
#[cfg(feature = "client")]
51+
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
5652
pub(super) use self::oneshot::{oneshot, Oneshot};
5753

5854
pub use self::make::make_service_fn;

0 commit comments

Comments
 (0)