Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid conflicts in case of consecutive underscores #321

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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