diff --git a/components/salsa-2022-macros/src/accumulator.rs b/components/salsa-2022-macros/src/accumulator.rs index 2f6b6221..4a6537d4 100644 --- a/components/salsa-2022-macros/src/accumulator.rs +++ b/components/salsa-2022-macros/src/accumulator.rs @@ -112,7 +112,7 @@ fn ingredients_for_impl( data_ty: &syn::Type, ) -> syn::ItemImpl { let jar_ty = args.jar_ty(); - let debug_name = proc_macro2::Literal::string(&struct_name.to_string()); + let debug_name = crate::literal(struct_name); parse_quote! { impl salsa::storage::IngredientsFor for #struct_name { type Ingredients = salsa::accumulator::AccumulatorIngredient<#data_ty>; diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index aa7fbf6b..9dc26d4a 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -130,17 +130,14 @@ impl InputStruct { /// The entity's ingredients include both the main entity ingredient along with a /// function ingredient for each of the value fields. fn input_ingredients(&self) -> syn::ItemImpl { + use crate::literal; let ident = self.id_ident(); let field_ty = self.all_field_tys(); let jar_ty = self.jar_ty(); let all_field_indices: Vec = self.all_field_indices(); let input_index: Literal = self.input_index(); - let debug_name_struct = Literal::string(&self.id_ident().to_string()); - let debug_name_fields: Vec<_> = self - .all_field_names() - .into_iter() - .map(|ident| Literal::string(&ident.to_string())) - .collect(); + let debug_name_struct = literal(self.id_ident()); + let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { diff --git a/components/salsa-2022-macros/src/lib.rs b/components/salsa-2022-macros/src/lib.rs index 13263b3b..45b31e67 100644 --- a/components/salsa-2022-macros/src/lib.rs +++ b/components/salsa-2022-macros/src/lib.rs @@ -25,6 +25,11 @@ macro_rules! parse_quote_spanned { } } +/// Convert a single Ident to Literal: useful when &'static str is needed. +pub(crate) fn literal(ident: &proc_macro2::Ident) -> proc_macro2::Literal { + proc_macro2::Literal::string(&ident.to_string()) +} + mod accumulator; mod configuration; mod db; diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 39547d1f..e62b5e54 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -243,7 +243,7 @@ fn ingredients_for_impl( let lru = args.lru.unwrap_or(0); // get the name of the function as a string literal - let debug_name = Literal::string(&item_fn.sig.ident.to_string()); + let debug_name = crate::literal(&item_fn.sig.ident); parse_quote! { impl salsa::storage::IngredientsFor for #config_ty { diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index f8a49070..99f12b53 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -153,18 +153,15 @@ impl TrackedStruct { /// The tracked struct's ingredients include both the main tracked struct ingredient along with a /// function ingredient for each of the value fields. fn tracked_struct_ingredients(&self, config_structs: &[syn::ItemStruct]) -> syn::ItemImpl { + use crate::literal; let ident = self.id_ident(); let jar_ty = self.jar_ty(); let id_field_tys: Vec<&syn::Type> = self.id_fields().map(SalsaField::ty).collect(); let value_field_indices: Vec = self.value_field_indices(); let tracked_struct_index: Literal = self.tracked_struct_index(); let config_struct_names = config_structs.iter().map(|s| &s.ident); - let debug_name_struct = Literal::string(&self.id_ident().to_string()); - let debug_name_fields: Vec<_> = self - .all_field_names() - .into_iter() - .map(|ident| Literal::string(&ident.to_string())) - .collect(); + let debug_name_struct = literal(self.id_ident()); + let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident {