Skip to content

Commit

Permalink
Merge pull request #1668 from dtolnay/foldhelper
Browse files Browse the repository at this point in the history
Eliminate FoldHelper trait
  • Loading branch information
dtolnay committed May 19, 2024
2 parents 6e20bb8 + ed54092 commit 4cd1813
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 133 deletions.
14 changes: 10 additions & 4 deletions codegen/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn visit(
let Type::Syn(t) = &**t else { unimplemented!() };
let method = method_name(t);
Some(quote! {
FoldHelper::lift(#name, f, F::#method)
fold_vec(#name, f, F::#method)
})
}
Type::Punctuated(p) => {
Expand Down Expand Up @@ -230,9 +230,6 @@ pub fn generate(defs: &Definitions) -> Result<()> {
clippy::needless_pass_by_ref_mut,
)]

#[cfg(any(feature = "full", feature = "derive"))]
use crate::gen::helper::fold::FoldHelper;

#full_macro

/// Syntax tree traversal to transform the nodes of an owned syntax tree.
Expand All @@ -245,6 +242,15 @@ pub fn generate(defs: &Definitions) -> Result<()> {
}

#impls

#[cfg(any(feature = "derive", feature = "full"))]
fn fold_vec<T, V, F>(vec: Vec<T>, fold: &mut V, mut f: F) -> Vec<T>
where
V: ?Sized,
F: FnMut(&mut V, T) -> T,
{
vec.into_iter().map(|it| f(fold, it)).collect()
}
},
)?;
Ok(())
Expand Down
Loading

0 comments on commit 4cd1813

Please sign in to comment.