From 309d1bd9530eec2217134cb262760af1df42ee3b Mon Sep 17 00:00:00 2001 From: Dihan Nahdi <90670352+dihannahdi@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:06:40 +0700 Subject: [PATCH] feat: add `#[diagnostic::on_unimplemented]` to `IntoResponse` and `IntoResponseParts` (#3723) --- axum-core/src/response/into_response.rs | 3 +++ axum-core/src/response/into_response_parts.rs | 3 +++ .../tests/debug_handler/fail/single_wrong_return_tuple.stderr | 1 + axum-macros/tests/debug_handler/fail/wrong_return_tuple.stderr | 2 ++ axum-macros/tests/debug_handler/fail/wrong_return_type.stderr | 1 + 5 files changed, 10 insertions(+) diff --git a/axum-core/src/response/into_response.rs b/axum-core/src/response/into_response.rs index a311851c..5cb9187c 100644 --- a/axum-core/src/response/into_response.rs +++ b/axum-core/src/response/into_response.rs @@ -109,6 +109,9 @@ use std::{ /// let app = Router::new().route("/", get(|| async { MyBody })); /// # let _: Router = app; /// ``` +#[diagnostic::on_unimplemented( + note = "See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponse.html` for details" +)] pub trait IntoResponse { /// Create a response. #[must_use] diff --git a/axum-core/src/response/into_response_parts.rs b/axum-core/src/response/into_response_parts.rs index a142b50b..6106b46d 100644 --- a/axum-core/src/response/into_response_parts.rs +++ b/axum-core/src/response/into_response_parts.rs @@ -70,6 +70,9 @@ use std::{convert::Infallible, fmt}; /// SetHeader("x-foo", "custom") /// } /// ``` +#[diagnostic::on_unimplemented( + note = "See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponseParts.html` for details" +)] pub trait IntoResponseParts { /// The type returned in the event of an error. /// diff --git a/axum-macros/tests/debug_handler/fail/single_wrong_return_tuple.stderr b/axum-macros/tests/debug_handler/fail/single_wrong_return_tuple.stderr index 835de128..da8b0b88 100644 --- a/axum-macros/tests/debug_handler/fail/single_wrong_return_tuple.stderr +++ b/axum-macros/tests/debug_handler/fail/single_wrong_return_tuple.stderr @@ -9,6 +9,7 @@ help: the trait `IntoResponse` is not implemented for `NotIntoResponse` | 3 | struct NotIntoResponse; | ^^^^^^^^^^^^^^^^^^^^^^ + = note: See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponse.html` for details = help: the following other types implement trait `IntoResponse`: &'static [u8; N] &'static [u8] diff --git a/axum-macros/tests/debug_handler/fail/wrong_return_tuple.stderr b/axum-macros/tests/debug_handler/fail/wrong_return_tuple.stderr index abc2b6e5..75fe5c1f 100644 --- a/axum-macros/tests/debug_handler/fail/wrong_return_tuple.stderr +++ b/axum-macros/tests/debug_handler/fail/wrong_return_tuple.stderr @@ -15,6 +15,7 @@ help: the trait `IntoResponseParts` is not implemented for `CustomIntoResponse` | 12 | struct CustomIntoResponse {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponseParts.html` for details = help: the following other types implement trait `IntoResponseParts`: () (T1, T2) @@ -42,6 +43,7 @@ help: the trait `IntoResponseParts` is not implemented for `CustomIntoResponse` | 12 | struct CustomIntoResponse {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponseParts.html` for details = help: the following other types implement trait `IntoResponseParts`: () (T1, T2) diff --git a/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr b/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr index c305e7e7..13a7435c 100644 --- a/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr +++ b/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr @@ -4,6 +4,7 @@ error[E0277]: the trait bound `bool: IntoResponse` is not satisfied 4 | async fn handler() -> bool { | ^^^^ the trait `IntoResponse` is not implemented for `bool` | + = note: See `https://docs.rs/axum/0.8/axum/response/trait.IntoResponse.html` for details = help: the following other types implement trait `IntoResponse`: &'static [u8; N] &'static [u8]