Skip to content

Commit

Permalink
refactor(ast_tools): only use type names to ignore fields in the `Der…
Browse files Browse the repository at this point in the history
…iveContentHash`.
  • Loading branch information
rzvxa committed Sep 7, 2024
1 parent 7f7ed7b commit 45ca309
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions tasks/ast_tools/src/derives/content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ define_derive! {
pub struct DeriveContentHash;
}

const IGNORE_FIELDS: [(/* field name */ &str, /* field type */ &str); 6] = [
("span", "Span"),
("trailing_comma", "Span"),
("this_span", "Span"),
("scope_id", "ScopeId"),
("symbol_id", "SymbolId"),
("reference_id", "ReferenceId"),
const IGNORE_FIELDS_TYPES: [/* type name */ &str; 4] = [
"Span",
"ScopeId",
"SymbolId",
"ReferenceId",
];

impl Derive for DeriveContentHash {
Expand Down Expand Up @@ -90,10 +88,7 @@ fn derive_struct(def: &StructDef) -> (&str, TokenStream) {
.fields
.iter()
.filter(|field| {
let Some(name) = field.name.as_ref() else { return false };
!IGNORE_FIELDS
.iter()
.any(|it| name == it.0 && field.typ.name().inner_name() == it.1)
!IGNORE_FIELDS_TYPES.iter().any(|it| field.typ.name().inner_name() == *it)
})
.map(|field| {
let ident = field.ident();
Expand Down

0 comments on commit 45ca309

Please sign in to comment.