Skip to content

Commit

Permalink
escape identifiers with _ to prevent keyword name collisions
Browse files Browse the repository at this point in the history
resolves #8
  • Loading branch information
PokeJofeJr4th committed Jul 17, 2023
1 parent 69da326 commit f283ab2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strum_macros/src/macros/enum_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn enum_map_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
};

let pascal_case = &variant.ident;
let snake_case = format_ident!("{}", snakify(&pascal_case.to_string()));
let snake_case = format_ident!("_{}", snakify(&pascal_case.to_string()));

get_matches.push(quote! {#name::#pascal_case => &self.#snake_case,});
get_matches_mut.push(quote! {#name::#pascal_case => &mut self.#snake_case,});
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ enum Color {
Indigo,
}

// even though this isn't used, it needs to be a test
// because if it doesn't compile, enum variants that conflict with keywords won't work
#[derive(EnumMap)]
enum Keyword {
Const,
Expand Down

0 comments on commit f283ab2

Please sign in to comment.