Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axum fails tests without default features, due to incompletely declared feature "json" #2835

Open
jonassmedegaard opened this issue Jul 18, 2024 · 5 comments

Comments

@jonassmedegaard
Copy link

Running cargo test --all-targets --no-default-features for crate axum v0.6.20 fails like this:

208s error[E0432]: unresolved import `crate::Json`
208s    --> src/routing/tests/mod.rs:15:26
208s     |
208s 15  |     BoxError, Extension, Json, Router,
208s     |                          ^^^^ no `Json` in the root
208s     |
208s     = help: consider importing this struct instead:
208s             tracing_subscriber::fmt::format::Json
208s note: found an item that was configured out
208s    --> src/lib.rs:481:21
208s     |
208s 481 | pub use self::json::Json;
208s     |                     ^^^^
208s     = note: the item is gated behind the `json` feature
208s 
208s error[E0432]: unresolved imports `crate::extract::OriginalUri`, `crate::Json`
208s    --> src/routing/tests/merge.rs:2:47
208s     |
208s 2   | use crate::{error_handling::HandleErrorLayer, extract::OriginalUri, response::IntoResponse, Json};
208s     |                                               ^^^^^^^^^^^^^^^^^^^^                          ^^^^ no `Json` in the root
208s     |                                               |
208s     |                                               no `OriginalUri` in `extract`
208s     |
208s note: found an item that was configured out
208s    --> src/extract/mod.rs:74:30
208s     |
208s 74  | pub use self::request_parts::OriginalUri;
208s     |                              ^^^^^^^^^^^
208s     = note: the item is gated behind the `original-uri` feature
208s     = help: consider importing one of these items instead:
208s             crate::routing::tests::Json
208s             tracing_subscriber::fmt::format::Json
208s note: found an item that was configured out
208s    --> src/lib.rs:481:21
208s     |
208s 481 | pub use self::json::Json;
208s     |                     ^^^^
208s     = note: the item is gated behind the `json` feature
208s 
208s error[E0432]: unresolved import `hyper::Server`
208s    --> src/test_helpers/test_client.rs:7:19
208s     |
208s 7   | use hyper::{Body, Server};
208s     |                   ^^^^^^ no `Server` in the root
208s     |
208s note: found an item that was configured out
208s    --> /usr/share/cargo/registry/hyper-0.14.27/src/lib.rs:110:28
208s     |
208s 110 |     pub use crate::server::Server;
208s     |                            ^^^^^^
208s     = note: the item is gated behind the `server` feature
208s 
208s error[E0432]: unresolved import `tower::make`
208s    --> src/test_helpers/test_client.rs:9:12
208s     |
208s 9   | use tower::make::Shared;
208s     |            ^^^^ could not find `make` in `tower`
208s     |
208s note: found an item that was configured out
208s    --> /usr/share/cargo/registry/tower-0.4.13/src/lib.rs:194:9
208s     |
208s 194 | pub mod make;
208s     |         ^^^^
208s     = note: the item is gated behind the `make` feature
208s 
208s error[E0433]: failed to resolve: could not find `Server` in the crate root
208s     --> src/routing/method_routing.rs:1394:16
208s      |
208s 1394 |         crate::Server::bind(&"0.0.0.0:0".parse().unwrap()).serve(app.into_make_service());
208s      |                ^^^^^^ could not find `Server` in the crate root
208s      |
208s note: found an item that was configured out
208s     --> src/lib.rs:475:16
208s      |
208s 475  | pub use hyper::Server;
208s      |                ^^^^^^
208s      = note: the item is gated behind the `tokio` feature
208s 
208s error[E0412]: cannot find type `OriginalUri` in module `extract`
208s    --> src/routing/tests/nest.rs:168:36
208s     |
208s 168 |                 get(|uri: extract::OriginalUri| async move { uri.0.to_string() }),
208s     |                                    ^^^^^^^^^^^ not found in `extract`
208s     |
208s note: found an item that was configured out
208s    --> src/extract/mod.rs:74:30
208s     |
208s 74  | pub use self::request_parts::OriginalUri;
208s     |                              ^^^^^^^^^^^
208s     = note: the item is gated behind the `original-uri` feature
208s 
208s warning: lint `private_in_public` has been removed: replaced with another group of lints, see RFC <https://rust-lang.github.io/rfcs/2145-type-privacy.html> for more information
208s    --> src/lib.rs:434:26
208s     |
208s 434 | #![deny(unreachable_pub, private_in_public)]
208s     |                          ^^^^^^^^^^^^^^^^^
208s     |
208s     = note: `#[warn(renamed_and_removed_lints)]` on by default
208s 
208s warning: unused imports: `Extension`, `FromRequestParts`
208s  --> src/extract/request_parts.rs:1:13
208s   |
208s 1 | use super::{Extension, FromRequest, FromRequestParts};
208s   |             ^^^^^^^^^               ^^^^^^^^^^^^^^^^
208s   |
208s   = note: `#[warn(unused_imports)]` on by default
208s 
208s warning: unused imports: `Uri`, `request::Parts`
208s  --> src/extract/request_parts.rs:8:12
208s   |
208s 8 | use http::{request::Parts, Request, Uri};
208s   |            ^^^^^^^^^^^^^^           ^^^
208s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:232:75
212s     |
212s 232 |     let one = Router::new().nest("/foo/", Router::new().route("/bar", get(all_the_uris)));
212s     |                                                                       --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                                                       |
212s     |                                                                       required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:233:47
212s     |
212s 233 |     let two = Router::new().route("/foo", get(all_the_uris));
212s     |                                           --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                           |
212s     |                                           required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:264:68
212s     |
212s 264 |         Router::new().nest("/bar", Router::new().route("/baz", get(all_the_uris))),
212s     |                                                                --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                                                |
212s     |                                                                required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:266:47
212s     |
212s 266 |     let two = Router::new().route("/foo", get(all_the_uris));
212s     |                                           --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                           |
212s     |                                           required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:297:68
212s     |
212s 297 |         Router::new().nest("/bar", Router::new().route("/baz", get(all_the_uris))),
212s     |                                                                --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                                                |
212s     |                                                                required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:299:74
212s     |
212s 299 |     let two = Router::new().nest("/two", Router::new().route("/qux", get(all_the_uris)));
212s     |                                                                      --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                                                      |
212s     |                                                                      required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:300:51
212s     |
212s 300 |     let three = Router::new().route("/three", get(all_the_uris));
212s     |                                               --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                               |
212s     |                                               required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:342:68
212s     |
212s 342 |         Router::new().nest("/foo", Router::new().route("/bar", get(all_the_uris))),
212s     |                                                                --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                                                |
212s     |                                                                required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
212s error[E0277]: the trait bound `fn(http::Uri, {type error}, http::Request<hyper::Body>) -> impl futures_util::Future<Output = impl axum_core::response::IntoResponse> {all_the_uris}: handler::Handler<_, _, _>` is not satisfied
212s    --> src/routing/tests/merge.rs:344:51
212s     |
212s 344 |     let two = Router::new().route("/two/foo", get(all_the_uris));
212s     |                                               --- ^^^^^^^^^^^^ the trait `handler::Handler<_, _, _>` is not implemented for fn item `fn(Uri, {type error}, Request<Body>) -> impl Future<Output = impl IntoResponse> {all_the_uris}`
212s     |                                               |
212s     |                                               required by a bound introduced by this call
212s     |
212s     = help: the following other types implement trait `handler::Handler<T, S, B>`:
212s               <handler::Layered<L, H, T, S, B, B2> as handler::Handler<T, S, B2>>
212s               <method_routing::MethodRouter<S, B> as handler::Handler<(), S, B>>
212s note: required by a bound in `method_routing::get`
212s    --> src/routing/method_routing.rs:145:16
212s     |
212s 145 |             H: Handler<T, S, B>,
212s     |                ^^^^^^^^^^^^^^^^ required by this bound in `get`
212s ...
212s 403 | top_level_handler_fn!(get, GET);
212s     | -------------------------------
212s     | |                     |
212s     | |                     required by a bound in this function
212s     | in this macro invocation
212s     = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
212s 
219s Some errors have detailed explanations: E0277, E0412, E0432, E0433.
219s For more information about an error, try `rustc --explain E0277`.
220s warning: `axum` (lib test) generated 3 warnings
220s error: could not compile `axum` (lib test) due to 24 previous errors; 3 warnings emitted

Applying the following patch, originally provided here, makes the test succeed:

Description: fix feature json
Author: Reinhard Tartler <[email protected]>
Bug-Debian: https://bugs.debian.org/1064232
Bug-Debian: https://bugs.debian.org/1076418
Last-Update: 2024-07-18
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/axum/Cargo.toml
+++ b/axum/Cargo.toml
@@ -16,7 +16,7 @@
 form = ["dep:serde_urlencoded"]
 http1 = ["hyper/http1"]
 http2 = ["hyper/http2"]
-json = ["dep:serde_json", "dep:serde_path_to_error"]
+json = ["dep:serde_json", "dep:serde_path_to_error", "original-uri", "tokio"]
 macros = ["dep:axum-macros"]
 matched-path = []
 multipart = ["dep:multer"]
@jplatte
Copy link
Member

jplatte commented Jul 18, 2024

There's a v0.6.x branch that you can make a PR to and I'd be happy to merge it, though right now I can't promise that it would ever make its way into a release. I don't think many crates in the Rust ecosystem care to be cargo testable from the tarballs uploaded to crates.io – though of course in this case the same issue applies to the git repo at the time of the release, and would be easy to fix.

If we never do another 0.6.x patch release otherwise, would there even be a point to fixing this if Debian is already patching it?

@jonassmedegaard
Copy link
Author

The reason I am reporting this issue is because others potentially might benefit from the bugfix currently applied to the code redistributed in Debian.

If Debian is the only place in the Universe still using axum v0.6 (or using it and caring about testability of unusual build scenarios) then arguably there is no point in moving bits from Debian maintenance to upstream git. I don't know the whole universe, though, so am not sure that I am in the best position to answer that question.

@jplatte
Copy link
Member

jplatte commented Jul 18, 2024

Want to send a PR then? As I said I'm happy to merge, and maybe David will put out a new release (I don't have publish access myself).

@jonassmedegaard
Copy link
Author

Want to send a PR then?

Thanks but no: I am fine just being the messenger here.

@jonassmedegaard
Copy link
Author

A related patch to cover other features than "json" exists here, in case someone finds an interest in that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants