Skip to content

Commit fd57d87

Browse files
authored
Improve error messages with #[diagnostic::do_not_recommend] (#3588)
1 parent e2d49c5 commit fd57d87

File tree

12 files changed

+40
-37
lines changed

12 files changed

+40
-37
lines changed

axum-core/src/extract/option.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pub trait OptionalFromRequest<S, M = private::ViaRequest>: Sized {
3535
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
3636
}
3737

38+
// Compiler hint just says that there is an impl for Option<T>, not mentioning
39+
// the bounds, which is not very helpful.
40+
#[diagnostic::do_not_recommend]
3841
impl<S, T> FromRequestParts<S> for Option<T>
3942
where
4043
T: OptionalFromRequestParts<S>,
@@ -51,6 +54,7 @@ where
5154
}
5255
}
5356

57+
#[diagnostic::do_not_recommend]
5458
impl<S, T> FromRequest<S> for Option<T>
5559
where
5660
T: OptionalFromRequest<S>,

axum-core/src/extract/request_parts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ where
6565
}
6666
}
6767

68+
#[diagnostic::do_not_recommend] // pretty niche impl
6869
impl<S> FromRequest<S> for BytesMut
6970
where
7071
S: Send + Sync,
@@ -136,6 +137,7 @@ where
136137
}
137138
}
138139

140+
#[diagnostic::do_not_recommend] // pretty niche impl
139141
impl<S> FromRequestParts<S> for Parts
140142
where
141143
S: Send + Sync,
@@ -147,6 +149,7 @@ where
147149
}
148150
}
149151

152+
#[diagnostic::do_not_recommend] // pretty niche impl
150153
impl<S> FromRequestParts<S> for Extensions
151154
where
152155
S: Send + Sync,

axum-core/src/extract/tuple.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::response::{IntoResponse, Response};
33
use http::request::Parts;
44
use std::{convert::Infallible, future::Future};
55

6+
#[diagnostic::do_not_recommend]
67
impl<S> FromRequestParts<S> for ()
78
where
89
S: Send + Sync,
@@ -18,6 +19,7 @@ macro_rules! impl_from_request {
1819
(
1920
[$($ty:ident),*], $last:ident
2021
) => {
22+
#[diagnostic::do_not_recommend]
2123
#[allow(non_snake_case, unused_mut, unused_variables)]
2224
impl<S, $($ty,)* $last> FromRequestParts<S> for ($($ty,)* $last,)
2325
where
@@ -43,6 +45,7 @@ macro_rules! impl_from_request {
4345

4446
// This impl must not be generic over M, otherwise it would conflict with the blanket
4547
// implementation of `FromRequest<S, Mut>` for `T: FromRequestParts<S>`.
48+
#[diagnostic::do_not_recommend]
4649
#[allow(non_snake_case, unused_mut, unused_variables)]
4750
impl<S, $($ty,)* $last> FromRequest<S> for ($($ty,)* $last,)
4851
where

axum-macros/tests/debug_handler/fail/argument_not_extractor.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ error[E0277]: the trait bound `bool: FromRequest<(), axum_core::extract::private
77
= note: Function argument is not a valid axum extractor.
88
See `https://docs.rs/axum/0.8/axum/extract/index.html` for details
99
= help: the following other types implement trait `FromRequestParts<S>`:
10-
`()` implements `FromRequestParts<S>`
11-
`(T1, T2)` implements `FromRequestParts<S>`
12-
`(T1, T2, T3)` implements `FromRequestParts<S>`
13-
`(T1, T2, T3, T4)` implements `FromRequestParts<S>`
14-
`(T1, T2, T3, T4, T5)` implements `FromRequestParts<S>`
15-
`(T1, T2, T3, T4, T5, T6)` implements `FromRequestParts<S>`
16-
`(T1, T2, T3, T4, T5, T6, T7)` implements `FromRequestParts<S>`
17-
`(T1, T2, T3, T4, T5, T6, T7, T8)` implements `FromRequestParts<S>`
10+
`ConnectInfo<T>` implements `FromRequestParts<S>`
11+
`Extension<T>` implements `FromRequestParts<S>`
12+
`HeaderMap` implements `FromRequestParts<S>`
13+
`MatchedPath` implements `FromRequestParts<S>`
14+
`Method` implements `FromRequestParts<S>`
15+
`OriginalUri` implements `FromRequestParts<S>`
16+
`Query<T>` implements `FromRequestParts<S>`
17+
`RawPathParams` implements `FromRequestParts<S>`
1818
and $N others
1919
= note: required for `bool` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
2020
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`

axum-macros/tests/debug_handler/fail/extension_not_clone.stderr

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ error[E0277]: the trait bound `NonCloneType: Clone` is not satisfied
55
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonCloneType`
66
|
77
= help: the following other types implement trait `FromRequest<S, M>`:
8-
(T1, T2)
9-
(T1, T2, T3)
10-
(T1, T2, T3, T4)
11-
(T1, T2, T3, T4, T5)
12-
(T1, T2, T3, T4, T5, T6)
13-
(T1, T2, T3, T4, T5, T6, T7)
14-
(T1, T2, T3, T4, T5, T6, T7, T8)
15-
(T1, T2, T3, T4, T5, T6, T7, T8, T9)
16-
and $N others
8+
Body
9+
Form<T>
10+
Json<T>
11+
RawForm
12+
Result<T, <T as FromRequest<S>>::Rejection>
13+
String
14+
axum::body::Bytes
15+
axum::http::Request<Body>
1716
= note: required for `Extension<NonCloneType>` to implement `FromRequestParts<()>`
1817
= note: required for `Extension<NonCloneType>` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
1918
note: required by a bound in `__axum_macros_check_test_extension_non_clone_0_from_request_check`

axum-macros/tests/from_request/fail/generic_without_via.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {fo
1313
| required by a bound introduced by this call
1414
|
1515
= note: Consider using `#[axum::debug_handler]` to improve the error message
16-
= help: the following other types implement trait `Handler<T, S>`:
17-
`Layered<L, H, T, S>` implements `Handler<T, S>`
18-
`MethodRouter<S>` implements `Handler<(), S>`
1916
note: required by a bound in `axum::routing::get`
2017
--> $WORKSPACE/axum/src/routing/method_routing.rs
2118
|

axum-macros/tests/from_request/fail/generic_without_via_rejection.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(Extractor<()>) -> impl Future<Output = ()> {fo
1313
| required by a bound introduced by this call
1414
|
1515
= note: Consider using `#[axum::debug_handler]` to improve the error message
16-
= help: the following other types implement trait `Handler<T, S>`:
17-
`Layered<L, H, T, S>` implements `Handler<T, S>`
18-
`MethodRouter<S>` implements `Handler<(), S>`
1916
note: required by a bound in `axum::routing::get`
2017
--> $WORKSPACE/axum/src/routing/method_routing.rs
2118
|

axum-macros/tests/from_request/fail/override_rejection_on_enum_without_via.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ error[E0277]: the trait bound `fn(MyExtractor) -> impl Future<Output = ()> {hand
1313
| required by a bound introduced by this call
1414
|
1515
= note: Consider using `#[axum::debug_handler]` to improve the error message
16-
= help: the following other types implement trait `Handler<T, S>`:
17-
`Layered<L, H, T, S>` implements `Handler<T, S>`
18-
`MethodRouter<S>` implements `Handler<(), S>`
1916
note: required by a bound in `axum::routing::get`
2017
--> $WORKSPACE/axum/src/routing/method_routing.rs
2118
|
@@ -35,9 +32,6 @@ error[E0277]: the trait bound `fn(Result<MyExtractor, MyRejection>) -> impl Futu
3532
| required by a bound introduced by this call
3633
|
3734
= note: Consider using `#[axum::debug_handler]` to improve the error message
38-
= help: the following other types implement trait `Handler<T, S>`:
39-
`Layered<L, H, T, S>` implements `Handler<T, S>`
40-
`MethodRouter<S>` implements `Handler<(), S>`
4135
note: required by a bound in `MethodRouter::<S>::post`
4236
--> $WORKSPACE/axum/src/routing/method_routing.rs
4337
|

axum-macros/tests/from_request/fail/parts_extracting_body.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ error[E0277]: the trait bound `String: FromRequestParts<_>` is not satisfied
77
= note: Function argument is not a valid axum extractor.
88
See `https://docs.rs/axum/0.8/axum/extract/index.html` for details
99
= help: the following other types implement trait `FromRequestParts<S>`:
10-
`()` implements `FromRequestParts<S>`
11-
`(T1, T2)` implements `FromRequestParts<S>`
12-
`(T1, T2, T3)` implements `FromRequestParts<S>`
13-
`(T1, T2, T3, T4)` implements `FromRequestParts<S>`
14-
`(T1, T2, T3, T4, T5)` implements `FromRequestParts<S>`
15-
`(T1, T2, T3, T4, T5, T6)` implements `FromRequestParts<S>`
16-
`(T1, T2, T3, T4, T5, T6, T7)` implements `FromRequestParts<S>`
17-
`(T1, T2, T3, T4, T5, T6, T7, T8)` implements `FromRequestParts<S>`
10+
`ConnectInfo<T>` implements `FromRequestParts<S>`
11+
`Extension<T>` implements `FromRequestParts<S>`
12+
`Extractor` implements `FromRequestParts<S>`
13+
`HeaderMap` implements `FromRequestParts<S>`
14+
`MatchedPath` implements `FromRequestParts<S>`
15+
`Method` implements `FromRequestParts<S>`
16+
`OriginalUri` implements `FromRequestParts<S>`
17+
`Query<T>` implements `FromRequestParts<S>`
1818
and $N others
1919

2020
error[E0282]: type annotations needed

axum/src/extract/nested_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl NestedPath {
4747
}
4848
}
4949

50+
#[diagnostic::do_not_recommend] // pretty niche type
5051
impl<S> FromRequestParts<S> for NestedPath
5152
where
5253
S: Send + Sync,

0 commit comments

Comments
 (0)