Skip to content

Commit 3348428

Browse files
committed
Assert that boxed source can be downcast
1 parent 1a000b4 commit 3348428

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tests/test_source.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::error::Error;
1+
use std::error::Error as StdError;
22
use std::io;
33
use thiserror::Error;
44

@@ -20,7 +20,7 @@ pub struct ExplicitSource {
2020
#[error("boxed source")]
2121
pub struct BoxedSource {
2222
#[source]
23-
source: Box<dyn Error + Send + 'static>,
23+
source: Box<dyn StdError + Send + 'static>,
2424
}
2525

2626
#[test]
@@ -42,8 +42,7 @@ fn test_explicit_source() {
4242

4343
#[test]
4444
fn test_boxed_source() {
45-
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
46-
let _error = BoxedSource {
47-
source: Box::new(io),
48-
};
45+
let source = Box::new(io::Error::new(io::ErrorKind::Other, "oh no!"));
46+
let error = BoxedSource { source };
47+
error.source().unwrap().downcast_ref::<io::Error>().unwrap();
4948
}

0 commit comments

Comments
 (0)