Skip to content

Commit febcc03

Browse files
authored
Merge pull request #451 from vip892766gma/maint/20260521171412
chore: improve thiserror maintenance path
2 parents d4a2507 + c50e387 commit febcc03

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_transparent.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ fn test_transparent_enum_with_default_message() {
6363
assert_eq!("inner", error.source().unwrap().to_string());
6464
}
6565

66+
#[test]
67+
fn test_transparent_enum_generic() {
68+
#[derive(Error, Debug)]
69+
enum Error<E> {
70+
#[error("this failed")]
71+
This,
72+
#[error(transparent)]
73+
Other(E),
74+
}
75+
76+
#[derive(Error, Debug)]
77+
#[error("inner error")]
78+
struct Inner;
79+
80+
let error = Error::<Inner>::This;
81+
assert_eq!("this failed", error.to_string());
82+
83+
let error = Error::Other(Inner);
84+
assert_eq!("inner error", error.to_string());
85+
assert!(error.source().is_none());
86+
87+
#[derive(Error, Debug)]
88+
#[error("wrapped")]
89+
struct WithSource(#[source] io::Error);
90+
91+
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
92+
let error = Error::Other(WithSource(io));
93+
assert_eq!("wrapped", error.to_string());
94+
assert_eq!("oh no!", error.source().unwrap().to_string());
95+
}
96+
6697
#[test]
6798
fn test_anyhow() {
6899
#[derive(Error, Debug)]

0 commit comments

Comments
 (0)