Skip to content

Commit

Permalink
fix: avoid conflicts in case of consecutive underscores (#321)
Browse files Browse the repository at this point in the history
* fix: avoid conflicts in case of consecutive underscores

* fix: suppress the warning for constant case
  • Loading branch information
aminya authored Jan 27, 2024
1 parent 83bcb98 commit 33b93b4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions strum_macros/src/macros/from_repr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use heck::ToShoutySnakeCase;
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{Data, DeriveInput, Fields, Type};
Expand Down Expand Up @@ -73,7 +72,7 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
};

let const_var_str = format!("{}_DISCRIMINANT", variant.ident).to_shouty_snake_case();
let const_var_str = format!("{}_DISCRIMINANT", variant.ident);
let const_var_ident = format_ident!("{}", const_var_str);

let const_val_expr = match &variant.discriminant {
Expand All @@ -84,7 +83,10 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
},
};

constant_defs.push(quote! {const #const_var_ident: #discriminant_type = #const_val_expr;});
constant_defs.push(quote! {
#[allow(non_upper_case_globals)]
const #const_var_ident: #discriminant_type = #const_val_expr;
});
arms.push(quote! {v if v == #const_var_ident => ::core::option::Option::Some(#name::#ident #params)});

prev_const_var_ident = Some(const_var_ident);
Expand Down

0 comments on commit 33b93b4

Please sign in to comment.