Skip to content

Commit 2117c97

Browse files
committed
Fix some of axum-macro's tests
1 parent 61bb214 commit 2117c97

28 files changed

+78
-67
lines changed

axum-macros/src/debug_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn check_inputs_impls_from_request(item_fn: &ItemFn, body_ty: &Type) -> TokenStr
196196
#[allow(warnings)]
197197
fn #name()
198198
where
199-
#ty: ::axum::extract::FromRequest<#body_ty> + Send,
199+
#ty: ::axum::extract::FromRequest<(), #body_ty> + Send,
200200
{}
201201
}
202202
})

axum-macros/src/from_request.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,17 @@ fn impl_struct_by_extracting_each_field(
106106
Ok(quote! {
107107
#[::axum::async_trait]
108108
#[automatically_derived]
109-
impl<B> ::axum::extract::FromRequest<B> for #ident
109+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
110110
where
111111
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
112112
B::Data: ::std::marker::Send,
113113
B::Error: ::std::convert::Into<::axum::BoxError>,
114+
S: Send,
114115
{
115116
type Rejection = #rejection_ident;
116117

117118
async fn from_request(
118-
req: &mut ::axum::extract::RequestParts<B>,
119+
req: &mut ::axum::extract::RequestParts<S, B>,
119120
) -> ::std::result::Result<Self, Self::Rejection> {
120121
::std::result::Result::Ok(Self {
121122
#(#extract_fields)*
@@ -301,7 +302,7 @@ fn extract_each_field_rejection(
301302

302303
Ok(quote_spanned! {ty_span=>
303304
#[allow(non_camel_case_types)]
304-
#variant_name(<#extractor_ty as ::axum::extract::FromRequest<::axum::body::Body>>::Rejection),
305+
#variant_name(<#extractor_ty as ::axum::extract::FromRequest<S, ::axum::body::Body>>::Rejection),
305306
})
306307
})
307308
.collect::<syn::Result<Vec<_>>>()?;
@@ -485,18 +486,19 @@ fn impl_struct_by_extracting_all_at_once(
485486
Ok(quote_spanned! {path_span=>
486487
#[::axum::async_trait]
487488
#[automatically_derived]
488-
impl<B> ::axum::extract::FromRequest<B> for #ident
489+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
489490
where
490491
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
491492
B::Data: ::std::marker::Send,
492493
B::Error: ::std::convert::Into<::axum::BoxError>,
494+
S: Send,
493495
{
494-
type Rejection = <#path<Self> as ::axum::extract::FromRequest<B>>::Rejection;
496+
type Rejection = <#path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection;
495497

496498
async fn from_request(
497-
req: &mut ::axum::extract::RequestParts<B>,
499+
req: &mut ::axum::extract::RequestParts<S, B>,
498500
) -> ::std::result::Result<Self, Self::Rejection> {
499-
::axum::extract::FromRequest::<B>::from_request(req)
501+
::axum::extract::FromRequest::<S, B>::from_request(req)
500502
.await
501503
.map(|#path(inner)| inner)
502504
}
@@ -540,18 +542,19 @@ fn impl_enum_by_extracting_all_at_once(
540542
Ok(quote_spanned! {path_span=>
541543
#[::axum::async_trait]
542544
#[automatically_derived]
543-
impl<B> ::axum::extract::FromRequest<B> for #ident
545+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
544546
where
545547
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
546548
B::Data: ::std::marker::Send,
547549
B::Error: ::std::convert::Into<::axum::BoxError>,
550+
S: Send,
548551
{
549-
type Rejection = <#path<Self> as ::axum::extract::FromRequest<B>>::Rejection;
552+
type Rejection = <#path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection;
550553

551554
async fn from_request(
552-
req: &mut ::axum::extract::RequestParts<B>,
555+
req: &mut ::axum::extract::RequestParts<S, B>,
553556
) -> ::std::result::Result<Self, Self::Rejection> {
554-
::axum::extract::FromRequest::<B>::from_request(req)
557+
::axum::extract::FromRequest::<S, B>::from_request(req)
555558
.await
556559
.map(|#path(inner)| inner)
557560
}

axum-macros/src/typed_path.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ fn expand_named_fields(
127127
let from_request_impl = quote! {
128128
#[::axum::async_trait]
129129
#[automatically_derived]
130-
impl<B> ::axum::extract::FromRequest<B> for #ident
130+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
131131
where
132132
B: Send,
133+
S: Send,
133134
{
134135
type Rejection = #rejection_assoc_type;
135136

136-
async fn from_request(req: &mut ::axum::extract::RequestParts<B>) -> ::std::result::Result<Self, Self::Rejection> {
137+
async fn from_request(req: &mut ::axum::extract::RequestParts<S, B>) -> ::std::result::Result<Self, Self::Rejection> {
137138
::axum::extract::Path::from_request(req)
138139
.await
139140
.map(|path| path.0)
@@ -229,13 +230,14 @@ fn expand_unnamed_fields(
229230
let from_request_impl = quote! {
230231
#[::axum::async_trait]
231232
#[automatically_derived]
232-
impl<B> ::axum::extract::FromRequest<B> for #ident
233+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
233234
where
234235
B: Send,
236+
S: Send,
235237
{
236238
type Rejection = #rejection_assoc_type;
237239

238-
async fn from_request(req: &mut ::axum::extract::RequestParts<B>) -> ::std::result::Result<Self, Self::Rejection> {
240+
async fn from_request(req: &mut ::axum::extract::RequestParts<S, B>) -> ::std::result::Result<Self, Self::Rejection> {
239241
::axum::extract::Path::from_request(req)
240242
.await
241243
.map(|path| path.0)
@@ -310,13 +312,14 @@ fn expand_unit_fields(
310312
let from_request_impl = quote! {
311313
#[::axum::async_trait]
312314
#[automatically_derived]
313-
impl<B> ::axum::extract::FromRequest<B> for #ident
315+
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
314316
where
315317
B: Send,
318+
S: Send,
316319
{
317320
type Rejection = #rejection_assoc_type;
318321

319-
async fn from_request(req: &mut ::axum::extract::RequestParts<B>) -> ::std::result::Result<Self, Self::Rejection> {
322+
async fn from_request(req: &mut ::axum::extract::RequestParts<S, B>) -> ::std::result::Result<Self, Self::Rejection> {
320323
if req.uri().path() == <Self as ::axum_extra::routing::TypedPath>::PATH {
321324
Ok(Self)
322325
} else {
@@ -387,7 +390,7 @@ enum Segment {
387390

388391
fn path_rejection() -> TokenStream {
389392
quote! {
390-
<::axum::extract::Path<Self> as ::axum::extract::FromRequest<B>>::Rejection
393+
<::axum::extract::Path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection
391394
}
392395
}
393396

Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error[E0277]: the trait bound `bool: FromRequest<Body>` is not satisfied
1+
error[E0277]: the trait bound `bool: FromRequest<(), Body>` is not satisfied
22
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
33
|
44
4 | async fn handler(foo: bool) {}
5-
| ^^^^ the trait `FromRequest<Body>` is not implemented for `bool`
5+
| ^^^^ the trait `FromRequest<(), Body>` is not implemented for `bool`
66
|
7-
= help: the following other types implement trait `FromRequest<B>`:
8-
()
9-
(T1, T2)
10-
(T1, T2, T3)
11-
(T1, T2, T3, T4)
12-
(T1, T2, T3, T4, T5)
13-
(T1, T2, T3, T4, T5, T6)
14-
(T1, T2, T3, T4, T5, T6, T7)
15-
(T1, T2, T3, T4, T5, T6, T7, T8)
16-
and 33 others
7+
= help: the following other types implement trait `FromRequest<S, B>`:
8+
<() as FromRequest<S, B>>
9+
<(T1, T2) as FromRequest<S, B>>
10+
<(T1, T2, T3) as FromRequest<S, B>>
11+
<(T1, T2, T3, T4) as FromRequest<S, B>>
12+
<(T1, T2, T3, T4, T5) as FromRequest<S, B>>
13+
<(T1, T2, T3, T4, T5, T6) as FromRequest<S, B>>
14+
<(T1, T2, T3, T4, T5, T6, T7) as FromRequest<S, B>>
15+
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequest<S, B>>
16+
and 34 others
1717
= help: see issue #48214

axum-macros/tests/debug_handler/fail/extract_self_mut.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use axum_macros::debug_handler;
77
struct A;
88

99
#[async_trait]
10-
impl<B> FromRequest<B> for A
10+
impl<S, B> FromRequest<S, B> for A
1111
where
12-
B: Send + 'static,
12+
B: Send,
13+
S: Send,
1314
{
1415
type Rejection = ();
1516

16-
async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
17+
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
1718
unimplemented!()
1819
}
1920
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Handlers must only take owned values
2-
--> tests/debug_handler/fail/extract_self_mut.rs:23:22
2+
--> tests/debug_handler/fail/extract_self_mut.rs:24:22
33
|
4-
23 | async fn handler(&mut self) {}
4+
24 | async fn handler(&mut self) {}
55
| ^^^^^^^^^

axum-macros/tests/debug_handler/fail/extract_self_ref.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use axum_macros::debug_handler;
77
struct A;
88

99
#[async_trait]
10-
impl<B> FromRequest<B> for A
10+
impl<S, B> FromRequest<S, B> for A
1111
where
12-
B: Send + 'static,
12+
B: Send,
13+
S: Send,
1314
{
1415
type Rejection = ();
1516

16-
async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
17+
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
1718
unimplemented!()
1819
}
1920
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Handlers must only take owned values
2-
--> tests/debug_handler/fail/extract_self_ref.rs:23:22
2+
--> tests/debug_handler/fail/extract_self_ref.rs:24:22
33
|
4-
23 | async fn handler(&self) {}
4+
24 | async fn handler(&self) {}
55
| ^^^^^

axum-macros/tests/debug_handler/pass/result_impl_into_response.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ impl A {
120120
}
121121

122122
#[async_trait]
123-
impl<B> FromRequest<B> for A
123+
impl<S, B> FromRequest<S, B> for A
124124
where
125-
B: Send + 'static,
125+
B: Send,
126+
S: Send,
126127
{
127128
type Rejection = ();
128129

129-
async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
130+
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
130131
unimplemented!()
131132
}
132133
}

axum-macros/tests/debug_handler/pass/self_receiver.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use axum_macros::debug_handler;
77
struct A;
88

99
#[async_trait]
10-
impl<B> FromRequest<B> for A
10+
impl<S, B> FromRequest<S, B> for A
1111
where
12-
B: Send + 'static,
12+
B: Send,
13+
S: Send,
1314
{
1415
type Rejection = ();
1516

16-
async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
17+
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
1718
unimplemented!()
1819
}
1920
}

axum-macros/tests/from_request/pass/container.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Extractor {
1515

1616
fn assert_from_request()
1717
where
18-
Extractor: FromRequest<Body, Rejection = JsonRejection>,
18+
Extractor: FromRequest<(), Body, Rejection = JsonRejection>,
1919
{
2020
}
2121

axum-macros/tests/from_request/pass/derive_opt_out.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ struct Extractor {
1414
struct OtherExtractor;
1515

1616
#[async_trait]
17-
impl<B> FromRequest<B> for OtherExtractor
17+
impl<S, B> FromRequest<S, B> for OtherExtractor
1818
where
19-
B: Send + 'static,
19+
B: Send,
20+
S: Send,
2021
{
2122
type Rejection = OtherExtractorRejection;
2223

23-
async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
24+
async fn from_request(_req: &mut RequestParts<(), B>) -> Result<Self, Self::Rejection> {
2425
unimplemented!()
2526
}
2627
}

axum-macros/tests/from_request/pass/empty_named.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Extractor {}
55

66
fn assert_from_request()
77
where
8-
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
8+
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
99
{
1010
}
1111

axum-macros/tests/from_request/pass/empty_tuple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Extractor();
55

66
fn assert_from_request()
77
where
8-
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
8+
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
99
{
1010
}
1111

axum-macros/tests/from_request/pass/named.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Extractor {
1818

1919
fn assert_from_request()
2020
where
21-
Extractor: FromRequest<Body, Rejection = ExtractorRejection>,
21+
Extractor: FromRequest<(), Body, Rejection = ExtractorRejection>,
2222
{
2323
}
2424

axum-macros/tests/from_request/pass/named_via.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Extractor {
2525

2626
fn assert_from_request()
2727
where
28-
Extractor: FromRequest<Body, Rejection = ExtractorRejection>,
28+
Extractor: FromRequest<(), Body, Rejection = ExtractorRejection>,
2929
{
3030
}
3131

axum-macros/tests/from_request/pass/tuple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Extractor(axum::http::HeaderMap, String);
55

66
fn assert_from_request()
77
where
8-
Extractor: axum::extract::FromRequest<axum::body::Body>,
8+
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
99
{
1010
}
1111

axum-macros/tests/from_request/pass/tuple_same_type_twice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Payload {}
1313

1414
fn assert_from_request()
1515
where
16-
Extractor: axum::extract::FromRequest<axum::body::Body>,
16+
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
1717
{
1818
}
1919

axum-macros/tests/from_request/pass/tuple_same_type_twice_via.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Payload {}
2727

2828
fn assert_from_request()
2929
where
30-
Extractor: axum::extract::FromRequest<axum::body::Body>,
30+
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
3131
{
3232
}
3333

axum-macros/tests/from_request/pass/tuple_via.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct State;
99

1010
fn assert_from_request()
1111
where
12-
Extractor: axum::extract::FromRequest<axum::body::Body>,
12+
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
1313
{
1414
}
1515

axum-macros/tests/from_request/pass/unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Extractor;
55

66
fn assert_from_request()
77
where
8-
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
8+
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
99
{
1010
}
1111

axum-macros/tests/typed_path/fail/not_deserialize.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ error[E0277]: the trait bound `for<'de> MyPath: serde::de::Deserialize<'de>` is
1515
(T0, T1, T2, T3)
1616
and 138 others
1717
= note: required because of the requirements on the impl of `serde::de::DeserializeOwned` for `MyPath`
18-
= note: required because of the requirements on the impl of `FromRequest<B>` for `axum::extract::Path<MyPath>`
18+
= note: required because of the requirements on the impl of `FromRequest<S, B>` for `axum::extract::Path<MyPath>`
1919
= note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)

axum-macros/tests/typed_path/pass/customize_rejection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Default for MyRejection {
4040
}
4141

4242
fn main() {
43-
axum::Router::<axum::body::Body>::new()
43+
axum::Router::<(), axum::body::Body>::new()
4444
.typed_get(|_: Result<MyPathNamed, MyRejection>| async {})
4545
.typed_post(|_: Result<MyPathUnnamed, MyRejection>| async {})
4646
.typed_put(|_: Result<MyPathUnit, MyRejection>| async {});

axum-macros/tests/typed_path/pass/named_fields_struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct MyPath {
99
}
1010

1111
fn main() {
12-
axum::Router::<axum::body::Body>::new().route("/", axum::routing::get(|_: MyPath| async {}));
12+
axum::Router::<(), axum::body::Body>::new().route("/", axum::routing::get(|_: MyPath| async {}));
1313

1414
assert_eq!(MyPath::PATH, "/users/:user_id/teams/:team_id");
1515
assert_eq!(

0 commit comments

Comments
 (0)