Skip to content

Commit

Permalink
Fix Generics Issue with enum_is (Peternator7#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp authored Oct 15, 2023
1 parent 3664c5e commit 0199235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion strum_macros/src/macros/enum_is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
Data::Enum(v) => &v.variants,
_ => return Err(non_enum_error()),
};
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();

let enum_name = &ast.ident;
let variants: Vec<_> = variants
Expand Down Expand Up @@ -35,7 +36,7 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
.collect();

Ok(quote! {
impl #enum_name {
impl #impl_generics #enum_name #ty_generics #where_clause {
#(#variants)*
}
}
Expand Down
17 changes: 15 additions & 2 deletions strum_tests/tests/enum_is.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::borrow::Cow;
use strum::EnumIs;

mod core {} // ensure macros call `::core`

#[derive(EnumIs)]
enum LifeTimeTest<'a>{
One(Cow<'a, str>),
Two(&'a str)
}
#[derive(EnumIs)]
enum Foo {
Unit,
Expand All @@ -16,7 +21,15 @@ enum Foo {
#[allow(dead_code)]
Disabled,
}

#[test]
fn generics_test(){
let foo = LifeTimeTest::One(Cow::Borrowed("Hello"));
assert!(foo.is_one());
let foo = LifeTimeTest::Two("Hello");
assert!(foo.is_two());
let foo = LifeTimeTest::One(Cow::Owned("Hello".to_string()));
assert!(foo.is_one());
}
#[test]
fn simple_test() {
assert!(Foo::Unit.is_unit());
Expand Down

0 comments on commit 0199235

Please sign in to comment.