Improve error messages with #[diagnostic::do_not_recommend] (#3588)

This commit is contained in:
Jonas Platte
2025-12-27 10:22:51 +01:00
parent aba8046921
commit f72c298ee8
12 changed files with 40 additions and 37 deletions
+4
View File
@@ -35,6 +35,9 @@ pub trait OptionalFromRequest<S, M = private::ViaRequest>: Sized {
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
}
// Compiler hint just says that there is an impl for Option<T>, not mentioning
// the bounds, which is not very helpful.
#[diagnostic::do_not_recommend]
impl<S, T> FromRequestParts<S> for Option<T>
where
T: OptionalFromRequestParts<S>,
@@ -50,6 +53,7 @@ where
}
}
#[diagnostic::do_not_recommend]
impl<S, T> FromRequest<S> for Option<T>
where
T: OptionalFromRequest<S>,
+3
View File
@@ -65,6 +65,7 @@ where
}
}
#[diagnostic::do_not_recommend] // pretty niche impl
impl<S> FromRequest<S> for BytesMut
where
S: Send + Sync,
@@ -134,6 +135,7 @@ where
}
}
#[diagnostic::do_not_recommend] // pretty niche impl
impl<S> FromRequestParts<S> for Parts
where
S: Send + Sync,
@@ -145,6 +147,7 @@ where
}
}
#[diagnostic::do_not_recommend] // pretty niche impl
impl<S> FromRequestParts<S> for Extensions
where
S: Send + Sync,
+3
View File
@@ -3,6 +3,7 @@ use crate::response::{IntoResponse, Response};
use http::request::Parts;
use std::{convert::Infallible, future::Future};
#[diagnostic::do_not_recommend]
impl<S> FromRequestParts<S> for ()
where
S: Send + Sync,
@@ -18,6 +19,7 @@ macro_rules! impl_from_request {
(
[$($ty:ident),*], $last:ident
) => {
#[diagnostic::do_not_recommend]
#[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, $($ty,)* $last> FromRequestParts<S> for ($($ty,)* $last,)
where
@@ -43,6 +45,7 @@ macro_rules! impl_from_request {
// This impl must not be generic over M, otherwise it would conflict with the blanket
// implementation of `FromRequest<S, Mut>` for `T: FromRequestParts<S>`.
#[diagnostic::do_not_recommend]
#[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, $($ty,)* $last> FromRequest<S> for ($($ty,)* $last,)
where
@@ -7,14 +7,14 @@ error[E0277]: the trait bound `bool: FromRequest<(), axum_core::extract::private
= note: Function argument is not a valid axum extractor.
See `https://docs.rs/axum/0.8/axum/extract/index.html` for details
= help: the following other types implement trait `FromRequestParts<S>`:
`()` implements `FromRequestParts<S>`
`(T1, T2)` implements `FromRequestParts<S>`
`(T1, T2, T3)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6, T7)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6, T7, T8)` implements `FromRequestParts<S>`
`ConnectInfo<T>` implements `FromRequestParts<S>`
`Extension<T>` implements `FromRequestParts<S>`
`HeaderMap` implements `FromRequestParts<S>`
`MatchedPath` implements `FromRequestParts<S>`
`Method` implements `FromRequestParts<S>`
`OriginalUri` implements `FromRequestParts<S>`
`Query<T>` implements `FromRequestParts<S>`
`RawPathParams` implements `FromRequestParts<S>`
and $N others
= note: required for `bool` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`
@@ -5,15 +5,14 @@ error[E0277]: the trait bound `NonCloneType: Clone` is not satisfied
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonCloneType`, which is required by `Extension<NonCloneType>: FromRequest<(), _>`
|
= help: the following other types implement trait `FromRequest<S, M>`:
(T1, T2)
(T1, T2, T3)
(T1, T2, T3, T4)
(T1, T2, T3, T4, T5)
(T1, T2, T3, T4, T5, T6)
(T1, T2, T3, T4, T5, T6, T7)
(T1, T2, T3, T4, T5, T6, T7, T8)
(T1, T2, T3, T4, T5, T6, T7, T8, T9)
and $N others
Body
Form<T>
Json<T>
RawForm
Result<T, <T as FromRequest<S>>::Rejection>
String
axum::body::Bytes
axum::http::Request<Body>
= note: required for `Extension<NonCloneType>` to implement `FromRequestParts<()>`
= note: required for `Extension<NonCloneType>` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
note: required by a bound in `__axum_macros_check_test_extension_non_clone_0_from_request_check`
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {fo
| required by a bound introduced by this call
|
= note: Consider using `#[axum::debug_handler]` to improve the error message
= help: the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`
note: required by a bound in `axum::routing::get`
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {fo
| required by a bound introduced by this call
|
= note: Consider using `#[axum::debug_handler]` to improve the error message
= help: the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`
note: required by a bound in `axum::routing::get`
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(MyExtractor) -> impl Future<Output = ()> {hand
| required by a bound introduced by this call
|
= note: Consider using `#[axum::debug_handler]` to improve the error message
= help: the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`
note: required by a bound in `axum::routing::get`
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
@@ -35,9 +32,6 @@ error[E0277]: the trait bound `fn(Result<MyExtractor, MyRejection>) -> impl Futu
| required by a bound introduced by this call
|
= note: Consider using `#[axum::debug_handler]` to improve the error message
= help: the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`
note: required by a bound in `MethodRouter::<S>::post`
--> $WORKSPACE/axum/src/routing/method_routing.rs
|
@@ -7,12 +7,12 @@ error[E0277]: the trait bound `String: FromRequestParts<_>` is not satisfied
= note: Function argument is not a valid axum extractor.
See `https://docs.rs/axum/0.8/axum/extract/index.html` for details
= help: the following other types implement trait `FromRequestParts<S>`:
`()` implements `FromRequestParts<S>`
`(T1, T2)` implements `FromRequestParts<S>`
`(T1, T2, T3)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6, T7)` implements `FromRequestParts<S>`
`(T1, T2, T3, T4, T5, T6, T7, T8)` implements `FromRequestParts<S>`
`ConnectInfo<T>` implements `FromRequestParts<S>`
`Extension<T>` implements `FromRequestParts<S>`
`Extractor` implements `FromRequestParts<S>`
`HeaderMap` implements `FromRequestParts<S>`
`MatchedPath` implements `FromRequestParts<S>`
`Method` implements `FromRequestParts<S>`
`OriginalUri` implements `FromRequestParts<S>`
`Query<T>` implements `FromRequestParts<S>`
and $N others
+1
View File
@@ -47,6 +47,7 @@ impl NestedPath {
}
}
#[diagnostic::do_not_recommend] // pretty niche type
impl<S> FromRequestParts<S> for NestedPath
where
S: Send + Sync,
+4
View File
@@ -204,6 +204,7 @@ pub trait Handler<T, S>: Clone + Send + Sync + Sized + 'static {
}
}
#[diagnostic::do_not_recommend]
impl<F, Fut, Res, S> Handler<((),), S> for F
where
F: FnOnce() -> Fut + Clone + Send + Sync + 'static,
@@ -221,6 +222,7 @@ macro_rules! impl_handler {
(
[$($ty:ident),*], $last:ident
) => {
#[diagnostic::do_not_recommend]
#[allow(non_snake_case, unused_mut)]
impl<F, Fut, S, Res, M, $($ty,)* $last> Handler<(M, $($ty,)* $last,), S> for F
where
@@ -265,6 +267,7 @@ mod private {
pub enum IntoResponseHandler {}
}
#[diagnostic::do_not_recommend]
impl<T, S> Handler<private::IntoResponseHandler, S> for T
where
T: IntoResponse + Clone + Send + Sync + 'static,
@@ -310,6 +313,7 @@ where
}
}
#[diagnostic::do_not_recommend]
impl<H, S, T, L> Handler<T, S> for Layered<L, H, T, S>
where
L: Layer<HandlerService<H, T, S>> + Clone + Send + Sync + 'static,
+1
View File
@@ -1306,6 +1306,7 @@ where
}
}
#[diagnostic::do_not_recommend]
impl<S> Handler<(), S> for MethodRouter<S>
where
S: Clone + 'static,