Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pengowen123 committed Oct 17, 2017
1 parent 1a67b33 commit 30683a6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
34 changes: 21 additions & 13 deletions src/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ macro_rules! error_chain_processed {
}

links {
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path )
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path,
$link_trait_path:path )
$( #[$meta_links:meta] )*; ) *
}

Expand Down Expand Up @@ -68,7 +69,8 @@ macro_rules! error_chain_processed {
/// internals, containing:
/// - a backtrace, generated when the error is created.
/// - an error chain, used for the implementation of `Error::cause()`.
#[derive(Debug, $($derive),*)]
//#[derive(Debug, $($derive),*)]
#[derive(Debug)]
pub struct $error_name(
// The members must be `pub` for `links`.
/// The kind of the error.
Expand Down Expand Up @@ -146,7 +148,7 @@ macro_rules! error_chain_processed {
}

/// Construct a chained error from another boxed error and a kind, and generates a backtrace
pub fn with_boxed_chain<K>(error: Box<::std::error::Error + Send>, kind: K)
pub fn with_boxed_chain<K>(error: Box<Trait>, kind: K)
-> $error_name
where K: Into<$error_kind_name>
{
Expand Down Expand Up @@ -214,7 +216,7 @@ macro_rules! error_chain_processed {
fn from(e: $link_error_path) -> Self {
$error_name(
$error_kind_name::$link_variant(e.0),
e.1,
::State { next_error: e.1.next_error.map(|e| $crate::ConvertErrorTrait::convert(e)), backtrace: e.1.backtrace },
)
}
}
Expand Down Expand Up @@ -332,13 +334,9 @@ macro_rules! error_chain_processed {
EK: Into<$error_kind_name>;
}

<<<<<<< HEAD
impl<T, E> $result_ext_name<T> for ::std::result::Result<T, E> where E: ::std::error::Error + Send + 'static {
=======
impl<T, E> $result_ext_name<T, E> for ::std::result::Result<T, E>
impl<T, E> $result_ext_name<T> for ::std::result::Result<T, E>
where E: Trait + 'static
{
>>>>>>> Change `derive` block to take the derive macro name and path to the trait
fn chain_err<F, EK>(self, callback: F) -> ::std::result::Result<T, $error_name>
where F: FnOnce() -> EK,
EK: Into<$error_kind_name> {
Expand All @@ -358,8 +356,6 @@ macro_rules! error_chain_processed {
})
}
}


};
}

Expand Down Expand Up @@ -445,9 +441,21 @@ macro_rules! error_chain {
#[doc(hidden)]
macro_rules! create_super_trait {
($name:ident: $bound_1:path, $($rest:path),*) => {
trait $name: $bound_1 $(+ $rest)* {}
pub trait $name: $bound_1 $(+ $rest)* {}
impl<T: $bound_1 $(+ $rest)*> $name for T {}
};

pub trait ConvertErrorTrait {
type Target: ?Sized;
fn convert(self: Box<Self>) -> Box<Self::Target>;
}

impl<T: ?Sized + $bound_1 $(+ $rest)*> ConvertErrorTrait for T {
type Target = Trait + 'static;
fn convert(self: Box<Self>) -> Box<Self::Target> {
Box::new(self) as Box<Trait>
}
}
};
}

/// Macro used to manage the `backtrace` feature.
Expand Down
8 changes: 4 additions & 4 deletions src/example_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
pub mod inner {
error_chain! {
derive {
PartialEq, PartialEq<Error>
//PartialEq, PartialEq<Error>
}
}
}

error_chain! {
links {
Inner(inner::Error, inner::ErrorKind) #[doc = "Link to another `ErrorChain`."];
Inner(inner::Error, inner::ErrorKind, inner::Trait) #[doc = "Link to another `ErrorChain`."];
}
foreign_links {
//Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
Expand All @@ -41,11 +41,11 @@ error_chain! {
Custom
}
derive {
PartialEq, PartialEq<Error>
//PartialEq, PartialEq<Error>
}
}

//fn foo<T: PartialEq>() {}
//fn bar() {
//foo::<Error>();
//foo::<Error>();
//}
47 changes: 27 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(missing_docs)]
//#![deny(missing_docs)]
#![allow(unknown_lints)] // to be removed when unused_doc_comments lints is merged
#![doc(html_root_url = "https://docs.rs/error-chain/0.11.0-rc.2")]

Expand Down Expand Up @@ -563,13 +563,16 @@ pub trait ChainedError<S: ?Sized>: error::Error + Send + 'static {
type ErrorKind;

/// Constructs an error from a kind, and generates a backtrace.
fn from_kind(kind: Self::ErrorKind) -> Self where Self: Sized;
fn from_kind(kind: Self::ErrorKind) -> Self
where
Self: Sized;

/// Constructs a chained error from another error and a kind, and generates a backtrace.
fn with_chain<E, K>(error: E, kind: K) -> Self
where Self: Sized,
E: ToError + ::std::error::Error + Send + 'static,
K: Into<Self::ErrorKind>;
where
Self: Sized,
E: ToError + ::std::error::Error + Send + 'static,
K: Into<Self::ErrorKind>;

/// Returns the kind of the error.
fn kind(&self) -> &Self::ErrorKind;
Expand All @@ -584,18 +587,21 @@ pub trait ChainedError<S: ?Sized>: error::Error + Send + 'static {
/// context of this error.
///
/// The full cause chain and backtrace, if present, will be printed.
fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self> {
fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self, S> {
DisplayChain(self, PhantomData)
}

/// Extends the error chain with a new entry.
fn chain_err<F, EK>(self, error: F) -> Self
where F: FnOnce() -> EK,
EK: Into<Self::ErrorKind>;
where
F: FnOnce() -> EK,
EK: Into<Self::ErrorKind>;

/// Creates an error from its parts.
#[doc(hidden)]
fn new(kind: Self::ErrorKind, state: State<S>) -> Self where Self: Sized;
fn new(kind: Self::ErrorKind, state: State<S>) -> Self
where
Self: Sized;

/// Returns the first known backtrace, either from its State or from one
/// of the errors from `foreign_links`.
Expand All @@ -608,19 +614,19 @@ pub trait ToError {
fn to_error(&self) -> &(error::Error + Send + 'static);
}

impl<T: ?Sized + ToError + error::Error + Send + 'static> ToError for Box<T> {
fn to_error(&self) -> &(error::Error + Send + 'static) {
self
}
}

/// A struct which formats an error for output.
#[derive(Debug)]
<<<<<<< HEAD
pub struct DisplayChain<'a, T: 'a + ?Sized>(&'a T);

impl<'a, T> fmt::Display for DisplayChain<'a, T>
where T: ChainedError
=======
pub struct Display<'a, T: 'a + ?Sized, S: ?Sized>(&'a T, PhantomData<S>);
pub struct DisplayChain<'a, T: 'a + ?Sized, S: ?Sized>(&'a T, PhantomData<S>);

impl<'a, T, S> fmt::Display for Display<'a, T, S>
where T: ChainedError<S>
>>>>>>> Add generic parameter to some types (errors can now add trait bounds)
impl<'a, T, S> fmt::Display for DisplayChain<'a, T, S>
where
T: ChainedError<S>,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
// Keep `try!` for 1.10 support
Expand Down Expand Up @@ -665,7 +671,8 @@ impl<T: ?Sized> Default for State<T> {
}

impl<T> State<T>
where T: ToError + ?Sized
where
T: ToError + ?Sized,
{
/// Creates a new State type
#[cfg(feature = "backtrace")]
Expand Down

0 comments on commit 30683a6

Please sign in to comment.