Skip to content

Commit

Permalink
Merge pull request #41 from mathstuf/support-non-sync-errors
Browse files Browse the repository at this point in the history
aserror: support Send + !Sync errors too
  • Loading branch information
dtolnay committed Nov 19, 2019
2 parents eb05272 + 4303f71 commit 1a000b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/aserror.rs
Expand Up @@ -18,6 +18,13 @@ impl AsDynError for dyn Error + 'static {
}
}

impl AsDynError for dyn Error + Send + 'static {
#[inline]
fn as_dyn_error(&self) -> &(dyn Error + 'static) {
self
}
}

impl AsDynError for dyn Error + Send + Sync + 'static {
#[inline]
fn as_dyn_error(&self) -> &(dyn Error + 'static) {
Expand Down
17 changes: 16 additions & 1 deletion tests/test_source.rs
@@ -1,4 +1,4 @@
use std::error::Error as _;
use std::error::Error;
use std::io;
use thiserror::Error;

Expand All @@ -16,6 +16,13 @@ pub struct ExplicitSource {
io: io::Error,
}

#[derive(Error, Debug)]
#[error("boxed source")]
pub struct BoxedSource {
#[source]
source: Box<dyn Error + Send + 'static>,
}

#[test]
fn test_implicit_source() {
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
Expand All @@ -32,3 +39,11 @@ fn test_explicit_source() {
};
error.source().unwrap().downcast_ref::<io::Error>().unwrap();
}

#[test]
fn test_boxed_source() {
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
let _error = BoxedSource {
source: Box::new(io),
};
}

0 comments on commit 1a000b4

Please sign in to comment.