From a508d86570d5ecaeed774e9a57a1fd847f3a7968 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 15 Oct 2021 12:05:56 +0200 Subject: [PATCH 1/4] Fix sometimes-unused dependencies --- tower/Cargo.toml | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/tower/Cargo.toml b/tower/Cargo.toml index f6cd032ac..4e0c3c479 100644 --- a/tower/Cargo.toml +++ b/tower/Cargo.toml @@ -25,6 +25,10 @@ edition = "2018" [features] default = ["log"] + +# Internal +__common = ["futures-core", "pin-project-lite"] + full = [ "balance", "buffer", @@ -43,30 +47,30 @@ full = [ "timeout", "util", ] +# FIXME: Use weak dependency once available (https://github.com/rust-lang/cargo/issues/8832) log = ["tracing/log"] -balance = ["discover", "load", "ready-cache", "make", "rand", "slab", "tokio-stream"] -buffer = ["tokio/sync", "tokio/rt", "tokio-util", "tracing"] -discover = [] -filter = ["futures-util"] +balance = ["discover", "load", "ready-cache", "make", "rand", "slab"] +buffer = ["__common", "tokio/sync", "tokio/rt", "tokio-util", "tracing"] +discover = ["__common"] +filter = ["__common", "futures-util"] hedge = ["util", "filter", "futures-util", "hdrhistogram", "tokio/time", "tracing"] -limit = ["tokio/time", "tokio/sync", "tokio-util", "tracing"] -load = ["tokio/time", "tracing"] -load-shed = [] -make = ["tokio/io-std", "futures-util"] -ready-cache = ["futures-util", "indexmap", "tokio/sync", "tracing"] +limit = ["__common", "tokio/time", "tokio/sync", "tokio-util", "tracing"] +load = ["__common", "tokio/time", "tracing"] +load-shed = ["__common"] +make = ["futures-util", "pin-project-lite", "tokio/io-std"] +ready-cache = ["futures-core", "futures-util", "indexmap", "tokio/sync", "tracing"] reconnect = ["make", "tokio/io-std", "tracing"] -retry = ["tokio/time"] -spawn-ready = ["futures-util", "tokio/sync", "tokio/rt", "util", "tracing"] -steer = ["futures-util"] -timeout = ["tokio/time"] -util = ["futures-util"] +retry = ["__common", "tokio/time"] +spawn-ready = ["__common", "futures-util", "tokio/sync", "tokio/rt", "util", "tracing"] +steer = [] +timeout = ["pin-project-lite", "tokio/time"] +util = ["__common", "futures-util", "pin-project"] [dependencies] -futures-core = "0.3" -pin-project = "1" tower-layer = { version = "0.3.1", path = "../tower-layer" } tower-service = { version = "0.3.1", path = "../tower-service" } +futures-core = { version = "0.3", optional = true } futures-util = { version = "0.3", default-features = false, features = ["alloc"], optional = true } hdrhistogram = { version = "7.0", optional = true } indexmap = { version = "1.0.2", optional = true } @@ -76,11 +80,13 @@ tokio = { version = "1", optional = true, features = ["sync"] } tokio-stream = { version = "0.1.0", optional = true } tokio-util = { version = "0.6.3", default-features = false, optional = true } tracing = { version = "0.1.2", default-features = false, features = ["std"], optional = true } -pin-project-lite = "0.2.7" +pin-project = { version = "1", optional = true } +pin-project-lite = { version = "0.2.7", optional = true } [dev-dependencies] futures = "0.3" hdrhistogram = "7.0" +pin-project-lite = "0.2.7" tokio = { version = "1", features = ["macros", "sync", "test-util", "rt-multi-thread"] } tokio-stream = "0.1" tokio-test = "0.4" From e280aef79b6167f1df0fe4558810c1fea12dfa70 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 15 Oct 2021 19:09:19 +0200 Subject: [PATCH 2/4] Remove html_root_url It is no longer recommended to set it: https://github.com/rust-lang/api-guidelines/pull/230 --- tower-layer/Cargo.toml | 1 - tower-layer/src/lib.rs | 1 - tower-service/Cargo.toml | 1 - tower-service/src/lib.rs | 1 - tower-test/Cargo.toml | 1 - tower-test/src/lib.rs | 1 - tower/Cargo.toml | 1 - tower/src/lib.rs | 1 - 8 files changed, 8 deletions(-) diff --git a/tower-layer/Cargo.toml b/tower-layer/Cargo.toml index dfe3dee93..74def8c09 100644 --- a/tower-layer/Cargo.toml +++ b/tower-layer/Cargo.toml @@ -2,7 +2,6 @@ name = "tower-layer" # When releasing to crates.io: # - Remove path dependencies -# - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md diff --git a/tower-layer/src/lib.rs b/tower-layer/src/lib.rs index 36245e028..218737550 100644 --- a/tower-layer/src/lib.rs +++ b/tower-layer/src/lib.rs @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tower-layer/0.3.1")] #![warn( missing_debug_implementations, missing_docs, diff --git a/tower-service/Cargo.toml b/tower-service/Cargo.toml index 8670a6922..f227ed3da 100644 --- a/tower-service/Cargo.toml +++ b/tower-service/Cargo.toml @@ -2,7 +2,6 @@ name = "tower-service" # When releasing to crates.io: # - Remove path dependencies -# - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md diff --git a/tower-service/src/lib.rs b/tower-service/src/lib.rs index 974568e3b..c2f531e1a 100644 --- a/tower-service/src/lib.rs +++ b/tower-service/src/lib.rs @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tower-service/0.3.1")] #![warn( missing_debug_implementations, missing_docs, diff --git a/tower-test/Cargo.toml b/tower-test/Cargo.toml index 9d5767218..02ad3f0c3 100644 --- a/tower-test/Cargo.toml +++ b/tower-test/Cargo.toml @@ -2,7 +2,6 @@ name = "tower-test" # When releasing to crates.io: # - Remove path dependencies -# - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md diff --git a/tower-test/src/lib.rs b/tower-test/src/lib.rs index 7b7da48bd..d86ed3e60 100644 --- a/tower-test/src/lib.rs +++ b/tower-test/src/lib.rs @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tower-test/0.4.0")] #![warn( missing_debug_implementations, missing_docs, diff --git a/tower/Cargo.toml b/tower/Cargo.toml index 4e0c3c479..00705fdfe 100644 --- a/tower/Cargo.toml +++ b/tower/Cargo.toml @@ -2,7 +2,6 @@ name = "tower" # When releasing to crates.io: # - Remove path dependencies -# - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md diff --git a/tower/src/lib.rs b/tower/src/lib.rs index e5d963ef9..c7aa3c0be 100644 --- a/tower/src/lib.rs +++ b/tower/src/lib.rs @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tower/0.4.11")] #![warn( missing_debug_implementations, missing_docs, From 9789c09fa80b123fa025ab352f8441804bc2f0bc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 15 Oct 2021 19:14:17 +0200 Subject: [PATCH 3/4] Remove unnecessary item from release instructions Path dependencies are not problematic for publishing as long as a version is also specified. --- tower-layer/Cargo.toml | 1 - tower-service/Cargo.toml | 1 - tower-test/Cargo.toml | 1 - tower/Cargo.toml | 1 - 4 files changed, 4 deletions(-) diff --git a/tower-layer/Cargo.toml b/tower-layer/Cargo.toml index 74def8c09..0b085ce9d 100644 --- a/tower-layer/Cargo.toml +++ b/tower-layer/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tower-layer" # When releasing to crates.io: -# - Remove path dependencies # - Update doc url # - Cargo.toml # - README.md diff --git a/tower-service/Cargo.toml b/tower-service/Cargo.toml index f227ed3da..d336b00cc 100644 --- a/tower-service/Cargo.toml +++ b/tower-service/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tower-service" # When releasing to crates.io: -# - Remove path dependencies # - Update doc url # - Cargo.toml # - README.md diff --git a/tower-test/Cargo.toml b/tower-test/Cargo.toml index 02ad3f0c3..2c01cae21 100644 --- a/tower-test/Cargo.toml +++ b/tower-test/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tower-test" # When releasing to crates.io: -# - Remove path dependencies # - Update doc url # - Cargo.toml # - README.md diff --git a/tower/Cargo.toml b/tower/Cargo.toml index 00705fdfe..9ed88177b 100644 --- a/tower/Cargo.toml +++ b/tower/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tower" # When releasing to crates.io: -# - Remove path dependencies # - Update doc url # - Cargo.toml # - README.md From a864d793b43a213a0e41a8eb1f0c0107b5519c0b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 15 Oct 2021 19:08:25 +0200 Subject: [PATCH 4/4] Remove pin-project dependency The only thing it was generating is written out into the source instead. --- tower/Cargo.toml | 3 +-- tower/src/lib.rs | 2 +- tower/src/util/either.rs | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tower/Cargo.toml b/tower/Cargo.toml index 9ed88177b..dd04ba5dc 100644 --- a/tower/Cargo.toml +++ b/tower/Cargo.toml @@ -62,7 +62,7 @@ retry = ["__common", "tokio/time"] spawn-ready = ["__common", "futures-util", "tokio/sync", "tokio/rt", "util", "tracing"] steer = [] timeout = ["pin-project-lite", "tokio/time"] -util = ["__common", "futures-util", "pin-project"] +util = ["__common", "futures-util"] [dependencies] tower-layer = { version = "0.3.1", path = "../tower-layer" } @@ -78,7 +78,6 @@ tokio = { version = "1", optional = true, features = ["sync"] } tokio-stream = { version = "0.1.0", optional = true } tokio-util = { version = "0.6.3", default-features = false, optional = true } tracing = { version = "0.1.2", default-features = false, features = ["std"], optional = true } -pin-project = { version = "1", optional = true } pin-project-lite = { version = "0.2.7", optional = true } [dev-dependencies] diff --git a/tower/src/lib.rs b/tower/src/lib.rs index c7aa3c0be..080140864 100644 --- a/tower/src/lib.rs +++ b/tower/src/lib.rs @@ -4,7 +4,7 @@ rust_2018_idioms, unreachable_pub )] -#![forbid(unsafe_code)] +#![deny(unsafe_code)] #![allow(elided_lifetimes_in_paths, clippy::type_complexity)] #![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(docsrs, feature(doc_cfg))] diff --git a/tower/src/util/either.rs b/tower/src/util/either.rs index 5933755ef..3378a3b49 100644 --- a/tower/src/util/either.rs +++ b/tower/src/util/either.rs @@ -3,7 +3,6 @@ //! See [`Either`] documentation for more details. use futures_core::ready; -use pin_project::pin_project; use std::{ future::Future, pin::Pin, @@ -17,13 +16,29 @@ use tower_service::Service; /// Both services must be of the same request, response, and error types. /// [`Either`] is useful for handling conditional branching in service middleware /// to different inner service types. -#[pin_project(project = EitherProj)] #[derive(Clone, Debug)] pub enum Either { /// One type of backing [`Service`]. - A(#[pin] A), + A(A), /// The other type of backing [`Service`]. - B(#[pin] B), + B(B), +} + +impl Either { + #[allow(unsafe_code)] // pin-project-lite doesn't support tuple variants in enums + fn project(self: Pin<&mut Self>) -> EitherProj<'_, A, B> { + unsafe { + match self.get_unchecked_mut() { + Self::A(a) => EitherProj::A(Pin::new_unchecked(a)), + Self::B(b) => EitherProj::B(Pin::new_unchecked(b)), + } + } + } +} + +enum EitherProj<'p, A, B> { + A(Pin<&'p mut A>), + B(Pin<&'p mut B>), } impl Service for Either