Skip to content

Commit

Permalink
refactor(ast_tools): shorten code (#5915)
Browse files Browse the repository at this point in the history
#5904 reduced the generated code for `Visit` trait. Shorten the codegen a little after that change.
  • Loading branch information
overlookmotel committed Sep 20, 2024
1 parent eadffb9 commit b80a9ee
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,6 @@ impl<'a> VisitBuilder<'a> {
}
}

fn get_iter(&self) -> TokenStream {
if self.is_mut {
quote!(iter_mut)
} else {
quote!(iter)
}
}

fn get_visitor(
&mut self,
def: &TypeDef,
Expand Down Expand Up @@ -262,8 +254,7 @@ impl<'a> VisitBuilder<'a> {

let (walk_body, may_inline) = if collection {
let singular_visit = self.get_visitor(def, false, None);
let iter = self.get_iter();
let iter = if self.is_mut { quote!(it.#iter()) } else { quote!(it) };
let iter = if self.is_mut { quote!(it.iter_mut()) } else { quote!(it) };
(
quote! {
for el in #iter {
Expand Down Expand Up @@ -511,7 +502,7 @@ impl<'a> VisitBuilder<'a> {
}
},
TypeWrapper::VecOpt => {
let iter = self.get_iter();
let iter = if self.is_mut { quote!(iter_mut) } else { quote!(iter) };
quote! {
for #name in it.#name.#iter().flatten() {
visitor.#visit(#name #(#args)*);
Expand Down

0 comments on commit b80a9ee

Please sign in to comment.