From b3a3ef0b1311670f16e96f0f32e4a37fb31023d7 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 15 Jun 2022 16:08:34 -0700 Subject: [PATCH] fix rust-analyzer incorrect-ident-case diagnostic Using the derive macro in a project with rust-analyzer gives an error complaining that this generated code isn't in the SCREAMING_SNAKE_CASE form. This change makes this diagnostic message go away. --- derive/Cargo.toml | 1 + derive/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 938258c..b564b54 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -18,6 +18,7 @@ repository = "https://github.com/rust-fuzz/arbitrary" documentation = "https://docs.rs/arbitrary/" [dependencies] +heck = "0.4" proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = ['derive'] } diff --git a/derive/src/lib.rs b/derive/src/lib.rs index cd8f1b2..82a0fa5 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -1,5 +1,6 @@ extern crate proc_macro; +use heck::ToShoutySnakeCase; use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::*; @@ -13,7 +14,7 @@ pub fn derive_arbitrary(tokens: proc_macro::TokenStream) -> proc_macro::TokenStr build_arbitrary_lifetime(input.generics.clone()); let recursive_count = syn::Ident::new( - &format!("RECURSIVE_COUNT_{}", input.ident), + &format!("RECURSIVE_COUNT_{}", input.ident.to_string().to_shouty_snake_case()), Span::call_site(), );