From d2b8f505f136bbad0b3abffa3a8664a9439b305a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:14:41 +0000 Subject: [PATCH] refactor(ast_tools): `TypeDef::name` return a `&str` (#6776) It's generally an anti-pattern for functions to return `&String`. `&str` is preferable. --- tasks/ast_tools/src/generators/ast_kind.rs | 2 +- tasks/ast_tools/src/generators/visit.rs | 4 ++-- tasks/ast_tools/src/schema/defs.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index bd6c4ee2eee8a..f3ad6fac83cc0 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -86,7 +86,7 @@ impl Generator for AstKindGenerator { .into_iter() .filter(|def| { let is_visitable = def.visitable(); - let is_blacklisted = BLACK_LIST.contains(&def.name().as_str()); + let is_blacklisted = BLACK_LIST.contains(&def.name()); is_visitable && !is_blacklisted }) .map(|def| { diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index 28c1cf7fde5d6..1c27a11f72fca 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -14,7 +14,7 @@ use crate::{ markers::VisitArg, output, schema::{EnumDef, GetIdent, StructDef, ToType, TypeDef}, - util::{StrExt, ToIdent, TokenStreamExt, TypeWrapper}, + util::{StrExt, TokenStreamExt, TypeWrapper}, Generator, GeneratorOutput, }; @@ -187,7 +187,7 @@ impl<'a> VisitBuilder<'a> { let (ident, as_type) = { debug_assert!(def.visitable(), "{def:?}"); - let ident = def.name().to_ident(); + let ident = def.ident(); let as_type = def.to_type(); (ident, if collection { parse_quote!(Vec<'a, #as_type>) } else { as_type }) diff --git a/tasks/ast_tools/src/schema/defs.rs b/tasks/ast_tools/src/schema/defs.rs index 488c8789f1d28..1494a30cc9b5f 100644 --- a/tasks/ast_tools/src/schema/defs.rs +++ b/tasks/ast_tools/src/schema/defs.rs @@ -22,7 +22,7 @@ impl TypeDef { with_either!(self, it => it.id) } - pub fn name(&self) -> &String { + pub fn name(&self) -> &str { with_either!(self, it => &it.name) }