mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-03 17:52:18 +01:00
Fix #[debug_handler]
for multiple extractors (#552)
* Fix `#[debug_handler]` for multiple extractors It generated a function for each extractor to check the type but those functions didn't have unique names. Fixed by including all idents in the `arg: Extractor` token tree in the name of the function generated. Not sure there is a simpler way to fix it. * just use a counter * don't need visit feature anymore
This commit is contained in:
parent
69fee5864d
commit
27e848fbe8
3 changed files with 15 additions and 3 deletions
|
@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- None.
|
- Fix regression causing errors when `#[debug_handler]` was used on functions with multiple
|
||||||
|
extractors.
|
||||||
|
|
||||||
# 0.2.1 (19. October 2021)
|
# 0.2.1 (19. October 2021)
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,8 @@ mod debug_handler {
|
||||||
.sig
|
.sig
|
||||||
.inputs
|
.inputs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| {
|
.enumerate()
|
||||||
|
.map(|(idx, arg)| {
|
||||||
let (span, ty) = match arg {
|
let (span, ty) = match arg {
|
||||||
FnArg::Receiver(receiver) => {
|
FnArg::Receiver(receiver) => {
|
||||||
if receiver.reference.is_some() {
|
if receiver.reference.is_some() {
|
||||||
|
@ -227,7 +228,11 @@ mod debug_handler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let name = format_ident!("__axum_debug_check_{}_from_request", item_fn.sig.ident);
|
let name = format_ident!(
|
||||||
|
"__axum_debug_check_{}_{}_from_request",
|
||||||
|
item_fn.sig.ident,
|
||||||
|
idx
|
||||||
|
);
|
||||||
quote_spanned! {span=>
|
quote_spanned! {span=>
|
||||||
#[allow(warnings)]
|
#[allow(warnings)]
|
||||||
fn #name()
|
fn #name()
|
||||||
|
|
6
axum-debug/tests/pass/multiple_extractors.rs
Normal file
6
axum-debug/tests/pass/multiple_extractors.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
use axum_debug::debug_handler;
|
||||||
|
|
||||||
|
#[debug_handler]
|
||||||
|
async fn handler(_one: String, _two: String, _three: String) {}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in a new issue