Skip to content

Commit

Permalink
Improve debug_handler to use the correct span for specific bounds
Browse files Browse the repository at this point in the history
This results in better localised error messages, as they now point
directly to the corresponding argument instead of to the macro itself.
  • Loading branch information
weiznich committed Sep 30, 2022
1 parent b942481 commit d5d076d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions axum-macros/src/debug_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ fn check_inputs_impls_from_request(
};

let from_request_bound = if must_impl_from_request_parts {
quote! {
quote_spanned! { span =>
#ty: ::axum::extract::FromRequestParts<#state_ty> + Send
}
} else {
quote! {
quote_spanned! { span =>
#ty: ::axum::extract::FromRequest<#state_ty, #body_ty, M> + Send
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ error[E0277]: the trait bound `bool: FromRequestParts<()>` is not satisfied
and 25 others
= note: required because of the requirements on the impl of `FromRequest<(), Body, axum_core::extract::private::ViaParts>` for `bool`
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`
--> tests/debug_handler/fail/argument_not_extractor.rs:3:1
--> tests/debug_handler/fail/argument_not_extractor.rs:4:23
|
3 | #[debug_handler]
| ^^^^^^^^^^^^^^^^ required by this bound in `__axum_macros_check_handler_0_from_request_check`
4 | async fn handler(foo: bool) {}
| ---- required by a bound in this
= note: this error originates in the attribute macro `debug_handler` (in Nightly builds, run with -Z macro-backtrace for more info)
| ^^^^ required by this bound in `__axum_macros_check_handler_0_from_request_check`
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `String: FromRequestParts<()>` is not satisfied
--> tests/debug_handler/fail/doesnt_implement_from_request_parts.rs:4:1
--> tests/debug_handler/fail/doesnt_implement_from_request_parts.rs:5:21
|
4 | #[debug_handler]
| ^^^^^^^^^^^^^^^^ the trait `FromRequestParts<()>` is not implemented for `String`
5 | async fn handler(_: String, _: Method) {}
| ^^^^^^ the trait `FromRequestParts<()>` is not implemented for `String`
|
= help: the following other types implement trait `FromRequestParts<S>`:
<() as FromRequestParts<S>>
Expand All @@ -15,4 +15,3 @@ error[E0277]: the trait bound `String: FromRequestParts<()>` is not satisfied
<(T1, T2, T3, T4, T5, T6, T7, T8) as FromRequestParts<S>>
and 25 others
= help: see issue #48214
= note: this error originates in the attribute macro `debug_handler` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit d5d076d

Please sign in to comment.