fix(axum-macros): use OptionalFromRequest for Option<T> fields (#3760)

This commit is contained in:
patelshudhanshu1999-maker
2026-05-16 23:33:44 +02:00
committed by GitHub
parent a480d71f6d
commit 6ed9210351
7 changed files with 174 additions and 10 deletions
@@ -0,0 +1,15 @@
use axum::{routing::get, Router};
use axum_macros::FromRequest;
struct Payload;
#[derive(FromRequest)]
struct Args {
payload: Option<Payload>,
}
async fn handler(_: Args) {}
fn main() {
let _: Router = Router::new().route("/", get(handler));
}
@@ -0,0 +1,39 @@
error[E0277]: the trait bound `Payload: OptionalFromRequest<_, _>` is not satisfied
--> tests/from_request/fail/option_without_optional_from_request.rs:8:21
|
8 | payload: Option<Payload>,
| ^^^^^^^ unsatisfied trait bound
|
help: the trait `OptionalFromRequest<_, _>` is not implemented for `Payload`
--> tests/from_request/fail/option_without_optional_from_request.rs:4:1
|
4 | struct Payload;
| ^^^^^^^^^^^^^^
help: the trait `OptionalFromRequest<S>` is implemented for `Json<T>`
--> $WORKSPACE/axum/src/json.rs
|
| / impl<T, S> OptionalFromRequest<S> for Json<T>
| | where
| | T: DeserializeOwned,
| | S: Send + Sync,
| |___________________^
error[E0277]: the trait bound `Payload: OptionalFromRequest<_, _>` is not satisfied
--> tests/from_request/fail/option_without_optional_from_request.rs:8:14
|
8 | payload: Option<Payload>,
| ^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `OptionalFromRequest<_, _>` is not implemented for `Payload`
--> tests/from_request/fail/option_without_optional_from_request.rs:4:1
|
4 | struct Payload;
| ^^^^^^^^^^^^^^
help: the trait `OptionalFromRequest<S>` is implemented for `Json<T>`
--> $WORKSPACE/axum/src/json.rs
|
| / impl<T, S> OptionalFromRequest<S> for Json<T>
| | where
| | T: DeserializeOwned,
| | S: Send + Sync,
| |___________________^