Add special handling of FromRequest extractors not being the last arg (#1797)

This commit is contained in:
David Pedersen
2023-03-03 09:44:10 +01:00
committed by GitHub
parent 73be489e03
commit 416a0568d3
8 changed files with 157 additions and 33 deletions
@@ -1,7 +0,0 @@
use axum_macros::debug_handler;
use axum::http::Method;
#[debug_handler]
async fn handler(_: String, _: Method) {}
fn main() {}
@@ -1,20 +0,0 @@
error[E0277]: the trait bound `String: FromRequestParts<()>` is not satisfied
--> tests/debug_handler/fail/doesnt_implement_from_request_parts.rs:5:21
|
5 | async fn handler(_: String, _: Method) {}
| ^^^^^^ the trait `FromRequestParts<()>` is not implemented for `String`
|
= note: Function argument is not a valid axum extractor.
See `https://docs.rs/axum/latest/axum/extract/index.html` for details
= help: the following other types implement trait `FromRequestParts<S>`:
<() as FromRequestParts<S>>
<(T1, T2) as FromRequestParts<S>>
<(T1, T2, T3) as FromRequestParts<S>>
<(T1, T2, T3, T4) as FromRequestParts<S>>
<(T1, T2, T3, T4, T5) as FromRequestParts<S>>
<(T1, T2, T3, T4, T5, T6) as FromRequestParts<S>>
<(T1, T2, T3, T4, T5, T6, T7) as FromRequestParts<S>>
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequestParts<S>>
and 26 others
= help: see issue #48214
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
@@ -0,0 +1,10 @@
use axum_macros::debug_handler;
use axum::{Json, body::Bytes, http::{Method, Uri}};
#[debug_handler]
async fn one(_: Json<()>, _: String, _: Uri) {}
#[debug_handler]
async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
fn main() {}
@@ -0,0 +1,11 @@
error: Can't have two extractors that consume the request body. `Json<_>` and `String` both do that.
--> tests/debug_handler/fail/multiple_request_consumers.rs:5:14
|
5 | async fn one(_: Json<()>, _: String, _: Uri) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Can't have more than one extractor that consume the request body. `Json<_>`, `Bytes`, and `String` all do that.
--> tests/debug_handler/fail/multiple_request_consumers.rs:8:14
|
8 | async fn two(_: Json<()>, _: Method, _: Bytes, _: Uri, _: String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -0,0 +1,10 @@
use axum_macros::debug_handler;
use axum::{Json, http::Uri};
#[debug_handler]
async fn one(_: Json<()>, _: Uri) {}
#[debug_handler]
async fn two(_: String, _: Uri) {}
fn main() {}
@@ -0,0 +1,11 @@
error: `Json<_>` consumes the request body and thus must be the last argument to the handler function
--> tests/debug_handler/fail/wrong_order.rs:5:17
|
5 | async fn one(_: Json<()>, _: Uri) {}
| ^^^^^^^^
error: `String` consumes the request body and thus must be the last argument to the handler function
--> tests/debug_handler/fail/wrong_order.rs:8:17
|
8 | async fn two(_: String, _: Uri) {}
| ^^^^^^