Skip to content

Commit

Permalink
refactor(ast_tools): derives for ContentEq and ContentHash use sa…
Browse files Browse the repository at this point in the history
…me 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.
  • Loading branch information
overlookmotel committed Jan 11, 2025
1 parent dab7a51 commit 91b0134
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
16 changes: 2 additions & 14 deletions tasks/ast_tools/src/derives/content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/derives/content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 91b0134

Please sign in to comment.