Skip to content

Commit

Permalink
Allow unreachable code in #[debug_handler] (#2014)
Browse files Browse the repository at this point in the history
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
  • Loading branch information
alexander-jackson and davidpdrsn committed Jul 17, 2023
1 parent 078c7ca commit 21fb5f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions axum-macros/src/debug_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ fn check_inputs_impls_from_request(

quote_spanned! {span=>
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
fn #check_fn #check_fn_generics()
where
Expand All @@ -285,6 +286,7 @@ fn check_inputs_impls_from_request(
// we have to call the function to actually trigger a compile error
// since the function is generic, just defining it is not enough
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
fn #call_check_fn()
{
Expand Down Expand Up @@ -429,6 +431,7 @@ fn check_output_impls_into_response(item_fn: &ItemFn) -> TokenStream {
let make = if item_fn.sig.asyncness.is_some() {
quote_spanned! {span=>
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
async fn #make_value_name() -> #ty {
#declare_inputs
Expand All @@ -438,6 +441,7 @@ fn check_output_impls_into_response(item_fn: &ItemFn) -> TokenStream {
} else {
quote_spanned! {span=>
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
fn #make_value_name() -> #ty {
#declare_inputs
Expand All @@ -453,6 +457,7 @@ fn check_output_impls_into_response(item_fn: &ItemFn) -> TokenStream {
#make

#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
async fn #name() {
let value = #receiver #make_value_name().await;
Expand All @@ -465,6 +470,7 @@ fn check_output_impls_into_response(item_fn: &ItemFn) -> TokenStream {
} else {
quote_spanned! {span=>
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
async fn #name() {
#make
Expand Down Expand Up @@ -515,6 +521,7 @@ fn check_future_send(item_fn: &ItemFn) -> TokenStream {
if let Some(receiver) = self_receiver(item_fn) {
quote! {
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
fn #name() {
let future = #receiver #handler_name(#(#args),*);
Expand All @@ -524,6 +531,7 @@ fn check_future_send(item_fn: &ItemFn) -> TokenStream {
} else {
quote! {
#[allow(warnings)]
#[allow(unreachable_code)]
#[doc(hidden)]
fn #name() {
#item_fn
Expand Down
8 changes: 8 additions & 0 deletions axum-macros/tests/debug_handler/pass/deny_unreachable_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(unreachable_code)]

use axum::extract::Path;

#[axum_macros::debug_handler]
async fn handler(Path(_): Path<String>) {}

fn main() {}

0 comments on commit 21fb5f4

Please sign in to comment.