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

Commit 4cb94bc

Browse files
committed
Fix conflicts
1 parent ad0437c commit 4cb94bc

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/error_chain.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ macro_rules! impl_error_chain_processed {
4242
}
4343

4444
links {
45-
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path )
45+
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path,
46+
$link_trait_path:path )
4647
$( #[$meta_links:meta] )*; ) *
4748
}
4849

@@ -70,7 +71,8 @@ macro_rules! impl_error_chain_processed {
7071
/// internals, containing:
7172
/// - a backtrace, generated when the error is created.
7273
/// - an error chain, used for the implementation of `Error::cause()`.
73-
#[derive(Debug, $($derive),*)]
74+
//#[derive(Debug, $($derive),*)]
75+
#[derive(Debug)]
7476
pub struct $error_name(
7577
// The members must be `pub` for `links`.
7678
/// The kind of the error.
@@ -148,7 +150,7 @@ macro_rules! impl_error_chain_processed {
148150
}
149151

150152
/// Construct a chained error from another boxed error and a kind, and generates a backtrace
151-
pub fn with_boxed_chain<K>(error: Box<::std::error::Error + Send>, kind: K)
153+
pub fn with_boxed_chain<K>(error: Box<Trait>, kind: K)
152154
-> $error_name
153155
where K: Into<$error_kind_name>
154156
{
@@ -222,7 +224,7 @@ macro_rules! impl_error_chain_processed {
222224
fn from(e: $link_error_path) -> Self {
223225
$error_name(
224226
$error_kind_name::$link_variant(e.0),
225-
e.1,
227+
::State { next_error: e.1.next_error.map(|e| $crate::ConvertErrorTrait::convert(e)), backtrace: e.1.backtrace },
226228
)
227229
}
228230
}
@@ -332,7 +334,7 @@ macro_rules! impl_error_chain_processed {
332334
EK: Into<$error_kind_name>;
333335
}
334336

335-
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>
336338
where E: Trait + 'static
337339
{
338340
fn chain_err<F, EK>(self, callback: F) -> ::std::result::Result<T, $error_name>
@@ -354,8 +356,6 @@ macro_rules! impl_error_chain_processed {
354356
})
355357
}
356358
}
357-
358-
359359
};
360360
}
361361

@@ -440,9 +440,21 @@ macro_rules! error_chain {
440440
#[doc(hidden)]
441441
macro_rules! create_super_trait {
442442
($name:ident: $bound_1:path, $($rest:path),*) => {
443-
trait $name: $bound_1 $(+ $rest)* {}
443+
pub trait $name: $bound_1 $(+ $rest)* {}
444444
impl<T: $bound_1 $(+ $rest)*> $name for T {}
445-
};
445+
446+
pub trait ConvertErrorTrait {
447+
type Target: ?Sized;
448+
fn convert(self: Box<Self>) -> Box<Self::Target>;
449+
}
450+
451+
impl<T: ?Sized + $bound_1 $(+ $rest)*> ConvertErrorTrait for T {
452+
type Target = Trait + 'static;
453+
fn convert(self: Box<Self>) -> Box<Self::Target> {
454+
Box::new(self) as Box<Trait>
455+
}
456+
}
457+
};
446458
}
447459

448460
/// 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

+11-4
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")]
44

@@ -592,7 +592,8 @@ pub trait ChainedError<S: ?Sized>: error::Error + Send + 'static {
592592

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

@@ -609,7 +610,7 @@ pub trait ChainedError<S: ?Sized>: error::Error + Send + 'static {
609610
/// context of this error.
610611
///
611612
/// The full cause chain and backtrace, if present, will be printed.
612-
fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self> {
613+
fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self, S> {
613614
DisplayChain(self, PhantomData)
614615
}
615616

@@ -635,6 +636,12 @@ pub trait ToError {
635636
fn to_error(&self) -> &(error::Error + Send + 'static);
636637
}
637638

639+
impl<T: ?Sized + ToError + error::Error + Send + 'static> ToError for Box<T> {
640+
fn to_error(&self) -> &(error::Error + Send + 'static) {
641+
self
642+
}
643+
}
644+
638645
/// A struct which formats an error for output.
639646
#[derive(Debug)]
640647
pub struct DisplayChain<'a, T: 'a + ?Sized, S: ?Sized>(&'a T, PhantomData<S>);
@@ -681,7 +688,7 @@ impl<T: ?Sized> Default for State<T> {
681688

682689
impl<T> State<T>
683690
where
684-
T: error::Error + Send + 'static,
691+
T: ToError + ?Sized,
685692
{
686693
/// Creates a new State type
687694
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {

0 commit comments

Comments
 (0)