From 27e848fbe85fce1c4c0bd5dfd723d7d6ea3b0078 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 22 Nov 2021 10:28:43 +0100 Subject: [PATCH] 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 --- axum-debug/CHANGELOG.md | 3 ++- axum-debug/src/lib.rs | 9 +++++++-- axum-debug/tests/pass/multiple_extractors.rs | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 axum-debug/tests/pass/multiple_extractors.rs diff --git a/axum-debug/CHANGELOG.md b/axum-debug/CHANGELOG.md index 1457eed3..74c6d2c1 100644 --- a/axum-debug/CHANGELOG.md +++ b/axum-debug/CHANGELOG.md @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- Fix regression causing errors when `#[debug_handler]` was used on functions with multiple + extractors. # 0.2.1 (19. October 2021) diff --git a/axum-debug/src/lib.rs b/axum-debug/src/lib.rs index 76918a8b..e35c0ed4 100644 --- a/axum-debug/src/lib.rs +++ b/axum-debug/src/lib.rs @@ -206,7 +206,8 @@ mod debug_handler { .sig .inputs .iter() - .map(|arg| { + .enumerate() + .map(|(idx, arg)| { let (span, ty) = match arg { FnArg::Receiver(receiver) => { 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=> #[allow(warnings)] fn #name() diff --git a/axum-debug/tests/pass/multiple_extractors.rs b/axum-debug/tests/pass/multiple_extractors.rs new file mode 100644 index 00000000..d5de6a4e --- /dev/null +++ b/axum-debug/tests/pass/multiple_extractors.rs @@ -0,0 +1,6 @@ +use axum_debug::debug_handler; + +#[debug_handler] +async fn handler(_one: String, _two: String, _three: String) {} + +fn main() {}