Skip to content

Commit

Permalink
Add missing generics and trait bounds to FromString impl
Browse files Browse the repository at this point in the history
Fixes #441
  • Loading branch information
chanced authored and shepmaster committed Mar 11, 2024
1 parent 941abc5 commit 61388f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion snafu-derive/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ pub mod context_selector {
let parameterized_error_name = self.parameterized_error_name;
let error_constructor_name = self.error_constructor_name;
let construct_implicit_fields = self.construct_implicit_fields();
let original_generics_without_defaults = self.original_generics_without_defaults;
let construct_implicit_fields_with_source =
self.construct_implicit_fields_with_source();
let extended_where_clauses = self.extended_where_clauses();

// testme: transform

Expand All @@ -381,7 +383,10 @@ pub mod context_selector {
let message_field_name = &message_field.name;

quote! {
impl #crate_root::FromString for #parameterized_error_name {
impl<#(#original_generics_without_defaults,)*> #crate_root::FromString for #parameterized_error_name
where
#(#extended_where_clauses),*
{
type Source = #source_ty;

#[track_caller]
Expand Down
14 changes: 14 additions & 0 deletions tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ mod bounds {
enum Error<T: Display> {
#[snafu(display("Boom: {value}"))]
Boom { value: T },

#[snafu(whatever, display("{message}"))]
Whatever {
message: String,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
}

#[test]
Expand All @@ -88,6 +95,13 @@ mod bounds {
{
#[snafu(display("Boom: {value}"))]
Boom { value: T },

#[snafu(whatever, display("{message}"))]
Whatever {
message: String,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
}

#[test]
Expand Down

0 comments on commit 61388f5

Please sign in to comment.