Skip to content

Commit

Permalink
Fix some of axum-macro's tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Jul 11, 2022
1 parent 61bb214 commit 2117c97
Show file tree
Hide file tree
Showing 28 changed files with 78 additions and 67 deletions.
2 changes: 1 addition & 1 deletion axum-macros/src/debug_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn check_inputs_impls_from_request(item_fn: &ItemFn, body_ty: &Type) -> TokenStr
#[allow(warnings)]
fn #name()
where
#ty: ::axum::extract::FromRequest<#body_ty> + Send,
#ty: ::axum::extract::FromRequest<(), #body_ty> + Send,
{}
}
})
Expand Down
25 changes: 14 additions & 11 deletions axum-macros/src/from_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,17 @@ fn impl_struct_by_extracting_each_field(
Ok(quote! {
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
B::Data: ::std::marker::Send,
B::Error: ::std::convert::Into<::axum::BoxError>,
S: Send,
{
type Rejection = #rejection_ident;

async fn from_request(
req: &mut ::axum::extract::RequestParts<B>,
req: &mut ::axum::extract::RequestParts<S, B>,
) -> ::std::result::Result<Self, Self::Rejection> {
::std::result::Result::Ok(Self {
#(#extract_fields)*
Expand Down Expand Up @@ -301,7 +302,7 @@ fn extract_each_field_rejection(

Ok(quote_spanned! {ty_span=>
#[allow(non_camel_case_types)]
#variant_name(<#extractor_ty as ::axum::extract::FromRequest<::axum::body::Body>>::Rejection),
#variant_name(<#extractor_ty as ::axum::extract::FromRequest<S, ::axum::body::Body>>::Rejection),
})
})
.collect::<syn::Result<Vec<_>>>()?;
Expand Down Expand Up @@ -485,18 +486,19 @@ fn impl_struct_by_extracting_all_at_once(
Ok(quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
B::Data: ::std::marker::Send,
B::Error: ::std::convert::Into<::axum::BoxError>,
S: Send,
{
type Rejection = <#path<Self> as ::axum::extract::FromRequest<B>>::Rejection;
type Rejection = <#path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection;

async fn from_request(
req: &mut ::axum::extract::RequestParts<B>,
req: &mut ::axum::extract::RequestParts<S, B>,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::<B>::from_request(req)
::axum::extract::FromRequest::<S, B>::from_request(req)
.await
.map(|#path(inner)| inner)
}
Expand Down Expand Up @@ -540,18 +542,19 @@ fn impl_enum_by_extracting_all_at_once(
Ok(quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: ::axum::body::HttpBody + ::std::marker::Send + 'static,
B::Data: ::std::marker::Send,
B::Error: ::std::convert::Into<::axum::BoxError>,
S: Send,
{
type Rejection = <#path<Self> as ::axum::extract::FromRequest<B>>::Rejection;
type Rejection = <#path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection;

async fn from_request(
req: &mut ::axum::extract::RequestParts<B>,
req: &mut ::axum::extract::RequestParts<S, B>,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::<B>::from_request(req)
::axum::extract::FromRequest::<S, B>::from_request(req)
.await
.map(|#path(inner)| inner)
}
Expand Down
17 changes: 10 additions & 7 deletions axum-macros/src/typed_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ fn expand_named_fields(
let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: Send,
S: Send,
{
type Rejection = #rejection_assoc_type;

async fn from_request(req: &mut ::axum::extract::RequestParts<B>) -> ::std::result::Result<Self, Self::Rejection> {
async fn from_request(req: &mut ::axum::extract::RequestParts<S, B>) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::Path::from_request(req)
.await
.map(|path| path.0)
Expand Down Expand Up @@ -229,13 +230,14 @@ fn expand_unnamed_fields(
let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: Send,
S: Send,
{
type Rejection = #rejection_assoc_type;

async fn from_request(req: &mut ::axum::extract::RequestParts<B>) -> ::std::result::Result<Self, Self::Rejection> {
async fn from_request(req: &mut ::axum::extract::RequestParts<S, B>) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::Path::from_request(req)
.await
.map(|path| path.0)
Expand Down Expand Up @@ -310,13 +312,14 @@ fn expand_unit_fields(
let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived]
impl<B> ::axum::extract::FromRequest<B> for #ident
impl<S, B> ::axum::extract::FromRequest<S, B> for #ident
where
B: Send,
S: Send,
{
type Rejection = #rejection_assoc_type;

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

fn path_rejection() -> TokenStream {
quote! {
<::axum::extract::Path<Self> as ::axum::extract::FromRequest<B>>::Rejection
<::axum::extract::Path<Self> as ::axum::extract::FromRequest<S, B>>::Rejection
}
}

Expand Down
24 changes: 12 additions & 12 deletions axum-macros/tests/debug_handler/fail/argument_not_extractor.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0277]: the trait bound `bool: FromRequest<Body>` is not satisfied
error[E0277]: the trait bound `bool: FromRequest<(), Body>` is not satisfied
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
|
4 | async fn handler(foo: bool) {}
| ^^^^ the trait `FromRequest<Body>` is not implemented for `bool`
| ^^^^ the trait `FromRequest<(), Body>` is not implemented for `bool`
|
= help: the following other types implement trait `FromRequest<B>`:
()
(T1, T2)
(T1, T2, T3)
(T1, T2, T3, T4)
(T1, T2, T3, T4, T5)
(T1, T2, T3, T4, T5, T6)
(T1, T2, T3, T4, T5, T6, T7)
(T1, T2, T3, T4, T5, T6, T7, T8)
and 33 others
= help: the following other types implement trait `FromRequest<S, B>`:
<() as FromRequest<S, B>>
<(T1, T2) as FromRequest<S, B>>
<(T1, T2, T3) as FromRequest<S, B>>
<(T1, T2, T3, T4) as FromRequest<S, B>>
<(T1, T2, T3, T4, T5) as FromRequest<S, B>>
<(T1, T2, T3, T4, T5, T6) as FromRequest<S, B>>
<(T1, T2, T3, T4, T5, T6, T7) as FromRequest<S, B>>
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequest<S, B>>
and 34 others
= help: see issue #48214
7 changes: 4 additions & 3 deletions axum-macros/tests/debug_handler/fail/extract_self_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use axum_macros::debug_handler;
struct A;

#[async_trait]
impl<B> FromRequest<B> for A
impl<S, B> FromRequest<S, B> for A
where
B: Send + 'static,
B: Send,
S: Send,
{
type Rejection = ();

async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
Expand Down
4 changes: 2 additions & 2 deletions axum-macros/tests/debug_handler/fail/extract_self_mut.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Handlers must only take owned values
--> tests/debug_handler/fail/extract_self_mut.rs:23:22
--> tests/debug_handler/fail/extract_self_mut.rs:24:22
|
23 | async fn handler(&mut self) {}
24 | async fn handler(&mut self) {}
| ^^^^^^^^^
7 changes: 4 additions & 3 deletions axum-macros/tests/debug_handler/fail/extract_self_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use axum_macros::debug_handler;
struct A;

#[async_trait]
impl<B> FromRequest<B> for A
impl<S, B> FromRequest<S, B> for A
where
B: Send + 'static,
B: Send,
S: Send,
{
type Rejection = ();

async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
Expand Down
4 changes: 2 additions & 2 deletions axum-macros/tests/debug_handler/fail/extract_self_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Handlers must only take owned values
--> tests/debug_handler/fail/extract_self_ref.rs:23:22
--> tests/debug_handler/fail/extract_self_ref.rs:24:22
|
23 | async fn handler(&self) {}
24 | async fn handler(&self) {}
| ^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ impl A {
}

#[async_trait]
impl<B> FromRequest<B> for A
impl<S, B> FromRequest<S, B> for A
where
B: Send + 'static,
B: Send,
S: Send,
{
type Rejection = ();

async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
7 changes: 4 additions & 3 deletions axum-macros/tests/debug_handler/pass/self_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use axum_macros::debug_handler;
struct A;

#[async_trait]
impl<B> FromRequest<B> for A
impl<S, B> FromRequest<S, B> for A
where
B: Send + 'static,
B: Send,
S: Send,
{
type Rejection = ();

async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
async fn from_request(_req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Extractor {

fn assert_from_request()
where
Extractor: FromRequest<Body, Rejection = JsonRejection>,
Extractor: FromRequest<(), Body, Rejection = JsonRejection>,
{
}

Expand Down
7 changes: 4 additions & 3 deletions axum-macros/tests/from_request/pass/derive_opt_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ struct Extractor {
struct OtherExtractor;

#[async_trait]
impl<B> FromRequest<B> for OtherExtractor
impl<S, B> FromRequest<S, B> for OtherExtractor
where
B: Send + 'static,
B: Send,
S: Send,
{
type Rejection = OtherExtractorRejection;

async fn from_request(_req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
async fn from_request(_req: &mut RequestParts<(), B>) -> Result<Self, Self::Rejection> {
unimplemented!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/empty_named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Extractor {}

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/empty_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Extractor();

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Extractor {

fn assert_from_request()
where
Extractor: FromRequest<Body, Rejection = ExtractorRejection>,
Extractor: FromRequest<(), Body, Rejection = ExtractorRejection>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/named_via.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Extractor {

fn assert_from_request()
where
Extractor: FromRequest<Body, Rejection = ExtractorRejection>,
Extractor: FromRequest<(), Body, Rejection = ExtractorRejection>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Extractor(axum::http::HeaderMap, String);

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body>,
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Payload {}

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body>,
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Payload {}

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body>,
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/tuple_via.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct State;

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body>,
Extractor: axum::extract::FromRequest<(), axum::body::Body>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Extractor;

fn assert_from_request()
where
Extractor: axum::extract::FromRequest<axum::body::Body, Rejection = std::convert::Infallible>,
Extractor: axum::extract::FromRequest<(), axum::body::Body, Rejection = std::convert::Infallible>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/typed_path/fail/not_deserialize.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ error[E0277]: the trait bound `for<'de> MyPath: serde::de::Deserialize<'de>` is
(T0, T1, T2, T3)
and 138 others
= note: required because of the requirements on the impl of `serde::de::DeserializeOwned` for `MyPath`
= note: required because of the requirements on the impl of `FromRequest<B>` for `axum::extract::Path<MyPath>`
= note: required because of the requirements on the impl of `FromRequest<S, B>` for `axum::extract::Path<MyPath>`
= note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion axum-macros/tests/typed_path/pass/customize_rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Default for MyRejection {
}

fn main() {
axum::Router::<axum::body::Body>::new()
axum::Router::<(), axum::body::Body>::new()
.typed_get(|_: Result<MyPathNamed, MyRejection>| async {})
.typed_post(|_: Result<MyPathUnnamed, MyRejection>| async {})
.typed_put(|_: Result<MyPathUnit, MyRejection>| async {});
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/typed_path/pass/named_fields_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct MyPath {
}

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

assert_eq!(MyPath::PATH, "/users/:user_id/teams/:team_id");
assert_eq!(
Expand Down

0 comments on commit 2117c97

Please sign in to comment.