refactor: Avoid implicit precondition

This commit is contained in:
Martin Fischer 2023-02-10 08:51:15 +01:00 committed by Charlie Marsh
parent ac6c3affdd
commit fa191cceeb
2 changed files with 3 additions and 5 deletions

View file

@ -64,9 +64,8 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
let rule_code_prefix = super::rule_code_prefix::expand( let rule_code_prefix = super::rule_code_prefix::expand(
&Ident::new("Rule", Span::call_site()), &Ident::new("Rule", Span::call_site()),
&Ident::new("RuleCodePrefix", Span::call_site()), &Ident::new("RuleCodePrefix", Span::call_site()),
mapping.entries.iter().map(|(code, ..)| code), mapping.entries.iter().map(|(code, .., attr)| (code, attr)),
|code| code_to_name[code], |code| code_to_name[code],
mapping.entries.iter().map(|(.., attr)| attr),
); );
quote! { quote! {

View file

@ -7,9 +7,8 @@ use syn::{Attribute, Ident};
pub fn expand<'a>( pub fn expand<'a>(
rule_type: &Ident, rule_type: &Ident,
prefix_ident: &Ident, prefix_ident: &Ident,
variants: impl Iterator<Item = &'a Ident>, variants: impl Iterator<Item = (&'a Ident, &'a Vec<Attribute>)>,
variant_name: impl Fn(&str) -> &'a Ident, variant_name: impl Fn(&str) -> &'a Ident,
attr: impl Iterator<Item = &'a Vec<Attribute>>,
) -> proc_macro2::TokenStream { ) -> proc_macro2::TokenStream {
// Build up a map from prefix to matching RuleCodes. // Build up a map from prefix to matching RuleCodes.
let mut prefix_to_codes: BTreeMap<String, BTreeMap<String, Vec<Attribute>>> = let mut prefix_to_codes: BTreeMap<String, BTreeMap<String, Vec<Attribute>>> =
@ -17,7 +16,7 @@ pub fn expand<'a>(
let mut pl_codes = BTreeMap::new(); let mut pl_codes = BTreeMap::new();
for (variant, attr) in variants.zip(attr) { for (variant, attr) in variants {
let code_str = variant.to_string(); let code_str = variant.to_string();
let code_prefix_len = code_str let code_prefix_len = code_str
.chars() .chars()