@@ -158,6 +158,12 @@ macro_rules! declare_error_trait {
158158 /// type appropriate for a basic JSON data format.
159159 ///
160160 /// [example data format]: https://serde.rs/data-format.html
161+ #[ cfg_attr(
162+ not( no_diagnostic_namespace) ,
163+ diagnostic:: on_unimplemented(
164+ message = "the trait bound `{Self}: serde::de::Error` is not satisfied" ,
165+ )
166+ ) ]
161167 pub trait Error : Sized $( + $( $supertrait) ::+) * {
162168 /// Raised when there is general error when deserializing a type.
163169 ///
@@ -471,6 +477,12 @@ impl<'a> fmt::Display for Unexpected<'a> {
471477/// ));
472478/// # }
473479/// ```
480+ #[ cfg_attr(
481+ not( no_diagnostic_namespace) ,
482+ diagnostic:: on_unimplemented(
483+ message = "the trait bound `{Self}: serde::de::Expected` is not satisfied" ,
484+ )
485+ ) ]
474486pub trait Expected {
475487 /// Format an explanation of what data was being expected. Same signature as
476488 /// the `Display` and `Debug` traits.
@@ -534,6 +546,9 @@ impl Display for dyn Expected + '_ {
534546#[ cfg_attr(
535547 not( no_diagnostic_namespace) ,
536548 diagnostic:: on_unimplemented(
549+ // Prevents `serde_core::de::Deserialize` appearing in the error message
550+ // in projects with no direct dependency on serde_core.
551+ message = "the trait bound `{Self}: serde::Deserialize<'de>` is not satisfied" ,
537552 note = "for local types consider adding `#[derive(serde::Deserialize)]` to your `{Self}` type" ,
538553 note = "for types from other crates check whether the crate offers a `serde` feature flag" ,
539554 )
@@ -610,6 +625,12 @@ pub trait Deserialize<'de>: Sized {
610625/// lifetimes].
611626///
612627/// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html
628+ #[ cfg_attr(
629+ not( no_diagnostic_namespace) ,
630+ diagnostic:: on_unimplemented(
631+ message = "the trait bound `{Self}: serde::de::DeserializeOwned` is not satisfied" ,
632+ )
633+ ) ]
613634pub trait DeserializeOwned : for < ' de > Deserialize < ' de > { }
614635impl < T > DeserializeOwned for T where T : for < ' de > Deserialize < ' de > { }
615636
@@ -775,6 +796,12 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
775796/// # Ok(())
776797/// # }
777798/// ```
799+ #[ cfg_attr(
800+ not( no_diagnostic_namespace) ,
801+ diagnostic:: on_unimplemented(
802+ message = "the trait bound `{Self}: serde::de::DeserializeSeed<'de>` is not satisfied" ,
803+ )
804+ ) ]
778805pub trait DeserializeSeed < ' de > : Sized {
779806 /// The type produced by using this seed.
780807 type Value ;
@@ -911,6 +938,12 @@ where
911938/// a basic JSON `Deserializer`.
912939///
913940/// [example data format]: https://serde.rs/data-format.html
941+ #[ cfg_attr(
942+ not( no_diagnostic_namespace) ,
943+ diagnostic:: on_unimplemented(
944+ message = "the trait bound `{Self}: serde::de::Deserializer<'de>` is not satisfied" ,
945+ )
946+ ) ]
914947pub trait Deserializer < ' de > : Sized {
915948 /// The error type that can be returned if some error occurs during
916949 /// deserialization.
@@ -1267,6 +1300,12 @@ pub trait Deserializer<'de>: Sized {
12671300/// }
12681301/// }
12691302/// ```
1303+ #[ cfg_attr(
1304+ not( no_diagnostic_namespace) ,
1305+ diagnostic:: on_unimplemented(
1306+ message = "the trait bound `{Self}: serde::de::Visitor<'de>` is not satisfied" ,
1307+ )
1308+ ) ]
12701309pub trait Visitor < ' de > : Sized {
12711310 /// The value produced by this visitor.
12721311 type Value ;
@@ -1693,6 +1732,12 @@ pub trait Visitor<'de>: Sized {
16931732/// implementation of `SeqAccess` for a basic JSON data format.
16941733///
16951734/// [example data format]: https://serde.rs/data-format.html
1735+ #[ cfg_attr(
1736+ not( no_diagnostic_namespace) ,
1737+ diagnostic:: on_unimplemented(
1738+ message = "the trait bound `{Self}: serde::de::SeqAccess<'de>` is not satisfied" ,
1739+ )
1740+ ) ]
16961741pub trait SeqAccess < ' de > {
16971742 /// The error type that can be returned if some error occurs during
16981743 /// deserialization.
@@ -1775,6 +1820,12 @@ where
17751820/// implementation of `MapAccess` for a basic JSON data format.
17761821///
17771822/// [example data format]: https://serde.rs/data-format.html
1823+ #[ cfg_attr(
1824+ not( no_diagnostic_namespace) ,
1825+ diagnostic:: on_unimplemented(
1826+ message = "the trait bound `{Self}: serde::de::MapAccess<'de>` is not satisfied" ,
1827+ )
1828+ ) ]
17781829pub trait MapAccess < ' de > {
17791830 /// The error type that can be returned if some error occurs during
17801831 /// deserialization.
@@ -1967,6 +2018,12 @@ where
19672018/// implementation of `EnumAccess` for a basic JSON data format.
19682019///
19692020/// [example data format]: https://serde.rs/data-format.html
2021+ #[ cfg_attr(
2022+ not( no_diagnostic_namespace) ,
2023+ diagnostic:: on_unimplemented(
2024+ message = "the trait bound `{Self}: serde::de::EnumAccess<'de>` is not satisfied" ,
2025+ )
2026+ ) ]
19702027pub trait EnumAccess < ' de > : Sized {
19712028 /// The error type that can be returned if some error occurs during
19722029 /// deserialization.
@@ -2014,6 +2071,12 @@ pub trait EnumAccess<'de>: Sized {
20142071/// implementation of `VariantAccess` for a basic JSON data format.
20152072///
20162073/// [example data format]: https://serde.rs/data-format.html
2074+ #[ cfg_attr(
2075+ not( no_diagnostic_namespace) ,
2076+ diagnostic:: on_unimplemented(
2077+ message = "the trait bound `{Self}: serde::de::VariantAccess<'de>` is not satisfied" ,
2078+ )
2079+ ) ]
20172080pub trait VariantAccess < ' de > : Sized {
20182081 /// The error type that can be returned if some error occurs during
20192082 /// deserialization. Must match the error type of our `EnumAccess`.
0 commit comments