Keep Debug and Display as supertraits even in no_std

This commit is contained in:
David Tolnay
2017-04-07 09:00:00 -07:00
parent 21c2119349
commit a581c0d147
2 changed files with 10 additions and 6 deletions
+5 -3
View File
@@ -101,6 +101,8 @@ use std::error;
use collections::{String, Vec}; use collections::{String, Vec};
use core::fmt::{self, Display}; use core::fmt::{self, Display};
#[cfg(not(feature = "std"))]
use core::fmt::Debug;
use core::marker::PhantomData; use core::marker::PhantomData;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -122,7 +124,7 @@ pub use self::ignored_any::IgnoredAny;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
macro_rules! declare_error_trait { macro_rules! declare_error_trait {
(Error: Sized $(+ $($supertrait:ident)::*)*) => { (Error: Sized $(+ $($supertrait:ident)::+)*) => {
/// The `Error` trait allows `Deserialize` implementations to create descriptive /// The `Error` trait allows `Deserialize` implementations to create descriptive
/// error messages belonging to the `Deserializer` against which they are /// error messages belonging to the `Deserializer` against which they are
/// currently running. /// currently running.
@@ -136,7 +138,7 @@ macro_rules! declare_error_trait {
/// ///
/// Most deserializers should only need to provide the `Error::custom` method /// Most deserializers should only need to provide the `Error::custom` method
/// and inherit the default behavior for the other methods. /// and inherit the default behavior for the other methods.
pub trait Error: Sized $(+ $($supertrait)::*)* { pub trait Error: Sized $(+ $($supertrait)::+)* {
/// Raised when there is general error when deserializing a type. /// Raised when there is general error when deserializing a type.
/// ///
/// The message should not be capitalized and should not end with a period. /// The message should not be capitalized and should not end with a period.
@@ -254,7 +256,7 @@ macro_rules! declare_error_trait {
declare_error_trait!(Error: Sized + error::Error); declare_error_trait!(Error: Sized + error::Error);
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
declare_error_trait!(Error: Sized); declare_error_trait!(Error: Sized + Debug + Display);
/// `Unexpected` represents an unexpected invocation of any one of the `Visitor` /// `Unexpected` represents an unexpected invocation of any one of the `Visitor`
/// trait methods. /// trait methods.
+5 -3
View File
@@ -97,6 +97,8 @@ use std::error;
#[cfg(all(feature = "collections", not(feature = "std")))] #[cfg(all(feature = "collections", not(feature = "std")))]
use collections::string::String; use collections::string::String;
#[cfg(not(feature = "std"))]
use core::fmt::Debug;
use core::fmt::Display; use core::fmt::Display;
#[cfg(any(feature = "std", feature = "collections"))] #[cfg(any(feature = "std", feature = "collections"))]
use core::fmt::Write; use core::fmt::Write;
@@ -116,11 +118,11 @@ pub use self::impossible::Impossible;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
macro_rules! declare_error_trait { macro_rules! declare_error_trait {
(Error: Sized $(+ $($supertrait:ident)::*)*) => { (Error: Sized $(+ $($supertrait:ident)::+)*) => {
/// Trait used by `Serialize` implementations to generically construct /// Trait used by `Serialize` implementations to generically construct
/// errors belonging to the `Serializer` against which they are /// errors belonging to the `Serializer` against which they are
/// currently running. /// currently running.
pub trait Error: Sized $(+ $($supertrait)::*)* { pub trait Error: Sized $(+ $($supertrait)::+)* {
/// Raised when a `Serialize` implementation encounters a general /// Raised when a `Serialize` implementation encounters a general
/// error while serializing a type. /// error while serializing a type.
/// ///
@@ -154,7 +156,7 @@ macro_rules! declare_error_trait {
declare_error_trait!(Error: Sized + error::Error); declare_error_trait!(Error: Sized + error::Error);
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
declare_error_trait!(Error: Sized); declare_error_trait!(Error: Sized + Debug + Display);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////