Skip to content

Commit bd8c572

Browse files
authored
Disambiguate Error type in TryFrom (#29)
* disambiguate Error type in TryFrom * add testcase for enum with error variant
1 parent 93d83cd commit bd8c572

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Enum {
180180
impl #parent_impl core::convert::TryFrom<#parent_ident #parent_ty> for #child_ident #child_ty #parent_where {
181181
type Error = #error;
182182

183-
fn try_from(parent: #parent_ident #parent_ty) -> Result<Self, Self::Error> {
183+
fn try_from(parent: #parent_ident #parent_ty) -> Result<Self, <Self as core::convert::TryFrom<#parent_ident #parent_ty>>::Error> {
184184
match parent {
185185
#(#try_from_parent_arms),*,
186186
_ => Err(#error)

tests/it.rs

+15
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,18 @@ enum Whew<'a: 'b, 'b, 'c, T, U> {
7272
#[subenum(Phew)]
7373
B(&'b [&'c [U; 7]]),
7474
}
75+
76+
#[subenum(SubEnumWithErrorVariant)]
77+
#[derive(Debug, Clone, Copy, PartialEq)]
78+
enum EnumWithErrorVariant {
79+
#[subenum(SubEnumWithErrorVariant)]
80+
Error,
81+
}
82+
83+
#[test]
84+
fn test_enum_with_error_variant() {
85+
let a = EnumWithErrorVariant::Error;
86+
let b = SubEnumWithErrorVariant::try_from(a).unwrap();
87+
88+
assert_eq!(a, b);
89+
}

0 commit comments

Comments
 (0)