From 91b01345fc028a3a857d1d774e39c6fb433a8673 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sat, 11 Jan 2025 07:18:05 +0000 Subject: [PATCH] refactor(ast_tools): derives for `ContentEq` and `ContentHash` use same ignore list (#8427) Pure refactor. Share the same field ignore list between the codegens for deriving `ContentEq` and `ContentHash` to prevent them getting out of sync. --- tasks/ast_tools/src/derives/content_eq.rs | 16 ++-------------- tasks/ast_tools/src/derives/content_hash.rs | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/tasks/ast_tools/src/derives/content_eq.rs b/tasks/ast_tools/src/derives/content_eq.rs index 496a870403cfd..27fbf5d275a43 100644 --- a/tasks/ast_tools/src/derives/content_eq.rs +++ b/tasks/ast_tools/src/derives/content_eq.rs @@ -7,21 +7,12 @@ use crate::{ util::ToIdent, }; -use super::{define_derive, Derive}; +use super::{content_hash::IGNORE_FIELD_TYPES, define_derive, Derive}; pub struct DeriveContentEq; define_derive!(DeriveContentEq); -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"), -]; - impl Derive for DeriveContentEq { fn trait_name() -> &'static str { "ContentEq" @@ -86,10 +77,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_FIELD_TYPES.iter().any(|it| field.typ.name().inner_name() == *it) }) .map(|field| { let ident = field.ident(); diff --git a/tasks/ast_tools/src/derives/content_hash.rs b/tasks/ast_tools/src/derives/content_hash.rs index d44c1ea645690..7a4c0724ea6dc 100644 --- a/tasks/ast_tools/src/derives/content_hash.rs +++ b/tasks/ast_tools/src/derives/content_hash.rs @@ -13,7 +13,7 @@ pub struct DeriveContentHash; define_derive!(DeriveContentHash); -const IGNORE_FIELD_TYPES: [/* type name */ &str; 4] = [ +pub const IGNORE_FIELD_TYPES: [/* type name */ &str; 4] = [ "Span", "ScopeId", "SymbolId",