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

Commit 30683a6

Browse files
committed
Fix conflicts
1 parent 1a67b33 commit 30683a6

File tree

3 files changed

+52
-37
lines changed

3 files changed

+52
-37
lines changed

src/error_chain.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ macro_rules! error_chain_processed {
4040
}
4141

4242
links {
43-
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path )
43+
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path,
44+
$link_trait_path:path )
4445
$( #[$meta_links:meta] )*; ) *
4546
}
4647

@@ -68,7 +69,8 @@ macro_rules! error_chain_processed {
6869
/// internals, containing:
6970
/// - a backtrace, generated when the error is created.
7071
/// - an error chain, used for the implementation of `Error::cause()`.
71-
#[derive(Debug, $($derive),*)]
72+
//#[derive(Debug, $($derive),*)]
73+
#[derive(Debug)]
7274
pub struct $error_name(
7375
// The members must be `pub` for `links`.
7476
/// The kind of the error.
@@ -146,7 +148,7 @@ macro_rules! error_chain_processed {
146148
}
147149

148150
/// Construct a chained error from another boxed error and a kind, and generates a backtrace
149-
pub fn with_boxed_chain<K>(error: Box<::std::error::Error + Send>, kind: K)
151+
pub fn with_boxed_chain<K>(error: Box<Trait>, kind: K)
150152
-> $error_name
151153
where K: Into<$error_kind_name>
152154
{
@@ -214,7 +216,7 @@ macro_rules! error_chain_processed {
214216
fn from(e: $link_error_path) -> Self {
215217
$error_name(
216218
$error_kind_name::$link_variant(e.0),
217-
e.1,
219+
::State { next_error: e.1.next_error.map(|e| $crate::ConvertErrorTrait::convert(e)), backtrace: e.1.backtrace },
218220
)
219221
}
220222
}
@@ -332,13 +334,9 @@ macro_rules! error_chain_processed {
332334
EK: Into<$error_kind_name>;
333335
}
334336

335-
<<<<<<< HEAD
336-
impl<T, E> $result_ext_name<T> for ::std::result::Result<T, E> where E: ::std::error::Error + Send + 'static {
337-
=======
338-
impl<T, E> $result_ext_name<T, E> for ::std::result::Result<T, E>
337+
impl<T, E> $result_ext_name<T> for ::std::result::Result<T, E>
339338
where E: Trait + 'static
340339
{
341-
>>>>>>> Change `derive` block to take the derive macro name and path to the trait
342340
fn chain_err<F, EK>(self, callback: F) -> ::std::result::Result<T, $error_name>
343341
where F: FnOnce() -> EK,
344342
EK: Into<$error_kind_name> {
@@ -358,8 +356,6 @@ macro_rules! error_chain_processed {
358356
})
359357
}
360358
}
361-
362-
363359
};
364360
}
365361

@@ -445,9 +441,21 @@ macro_rules! error_chain {
445441
#[doc(hidden)]
446442
macro_rules! create_super_trait {
447443
($name:ident: $bound_1:path, $($rest:path),*) => {
448-
trait $name: $bound_1 $(+ $rest)* {}
444+
pub trait $name: $bound_1 $(+ $rest)* {}
449445
impl<T: $bound_1 $(+ $rest)*> $name for T {}
450-
};
446+
447+
pub trait ConvertErrorTrait {
448+
type Target: ?Sized;
449+
fn convert(self: Box<Self>) -> Box<Self::Target>;
450+
}
451+
452+
impl<T: ?Sized + $bound_1 $(+ $rest)*> ConvertErrorTrait for T {
453+
type Target = Trait + 'static;
454+
fn convert(self: Box<Self>) -> Box<Self::Target> {
455+
Box::new(self) as Box<Trait>
456+
}
457+
}
458+
};
451459
}
452460

453461
/// Macro used to manage the `backtrace` feature.

src/example_generated.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
pub mod inner {
2525
error_chain! {
2626
derive {
27-
PartialEq, PartialEq<Error>
27+
//PartialEq, PartialEq<Error>
2828
}
2929
}
3030
}
3131

3232
error_chain! {
3333
links {
34-
Inner(inner::Error, inner::ErrorKind) #[doc = "Link to another `ErrorChain`."];
34+
Inner(inner::Error, inner::ErrorKind, inner::Trait) #[doc = "Link to another `ErrorChain`."];
3535
}
3636
foreign_links {
3737
//Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
@@ -41,11 +41,11 @@ error_chain! {
4141
Custom
4242
}
4343
derive {
44-
PartialEq, PartialEq<Error>
44+
//PartialEq, PartialEq<Error>
4545
}
4646
}
4747

4848
//fn foo<T: PartialEq>() {}
4949
//fn bar() {
50-
//foo::<Error>();
50+
//foo::<Error>();
5151
//}

src/lib.rs

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(missing_docs)]
1+
//#![deny(missing_docs)]
22
#![allow(unknown_lints)] // to be removed when unused_doc_comments lints is merged
33
#![doc(html_root_url = "https://docs.rs/error-chain/0.11.0-rc.2")]
44

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

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

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

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

591594
/// Extends the error chain with a new entry.
592595
fn chain_err<F, EK>(self, error: F) -> Self
593-
where F: FnOnce() -> EK,
594-
EK: Into<Self::ErrorKind>;
596+
where
597+
F: FnOnce() -> EK,
598+
EK: Into<Self::ErrorKind>;
595599

596600
/// Creates an error from its parts.
597601
#[doc(hidden)]
598-
fn new(kind: Self::ErrorKind, state: State<S>) -> Self where Self: Sized;
602+
fn new(kind: Self::ErrorKind, state: State<S>) -> Self
603+
where
604+
Self: Sized;
599605

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

617+
impl<T: ?Sized + ToError + error::Error + Send + 'static> ToError for Box<T> {
618+
fn to_error(&self) -> &(error::Error + Send + 'static) {
619+
self
620+
}
621+
}
622+
611623
/// A struct which formats an error for output.
612624
#[derive(Debug)]
613-
<<<<<<< HEAD
614-
pub struct DisplayChain<'a, T: 'a + ?Sized>(&'a T);
615-
616-
impl<'a, T> fmt::Display for DisplayChain<'a, T>
617-
where T: ChainedError
618-
=======
619-
pub struct Display<'a, T: 'a + ?Sized, S: ?Sized>(&'a T, PhantomData<S>);
625+
pub struct DisplayChain<'a, T: 'a + ?Sized, S: ?Sized>(&'a T, PhantomData<S>);
620626

621-
impl<'a, T, S> fmt::Display for Display<'a, T, S>
622-
where T: ChainedError<S>
623-
>>>>>>> Add generic parameter to some types (errors can now add trait bounds)
627+
impl<'a, T, S> fmt::Display for DisplayChain<'a, T, S>
628+
where
629+
T: ChainedError<S>,
624630
{
625631
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
626632
// Keep `try!` for 1.10 support
@@ -665,7 +671,8 @@ impl<T: ?Sized> Default for State<T> {
665671
}
666672

667673
impl<T> State<T>
668-
where T: ToError + ?Sized
674+
where
675+
T: ToError + ?Sized,
669676
{
670677
/// Creates a new State type
671678
#[cfg(feature = "backtrace")]

0 commit comments

Comments
 (0)