Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Fold/VisitMut methods for Vec<T>, Option<T>, Punctuated, etc. #1599

Closed
programmerjake opened this issue Mar 20, 2024 · 5 comments · Fixed by #1762
Closed

add Fold/VisitMut methods for Vec<T>, Option<T>, Punctuated, etc. #1599

programmerjake opened this issue Mar 20, 2024 · 5 comments · Fixed by #1762

Comments

@programmerjake
Copy link
Contributor

programmerjake commented Mar 20, 2024

I'm trying to build a Fold visitor that removes all Attributes that match a pattern, using Fold::fold_attribute doesn't work because I want to replace the attribute with nothing, not another attribute.

I think adding Fold::fold_attributes is a good solution.

I also ran into this problem when trying to transform Stmt into nothing, I had to construct a no-op Stmt.

@programmerjake
Copy link
Contributor Author

as mentioned above, this is also a problem for Stmt and other things where you have a list of them, the PR just fixed the problem for attributes.

@dtolnay
Copy link
Owner

dtolnay commented Oct 20, 2024

Vec<Stmt> is exclusively present in Block so it can easily be handled in fold_block already.

@programmerjake
Copy link
Contributor Author

that takes care of Vec<Stmt> but not the many instances of Punctuated, e.g. there's several places where there's Punctuated<Expr, _> and Punctuated<Pat, _>

@dtolnay
Copy link
Owner

dtolnay commented Oct 20, 2024

What use case did you have for a method dedicated to those?

@programmerjake
Copy link
Contributor Author

programmerjake commented Oct 20, 2024

well, for fields I've written proc macros that transform type definitions by removing fields that have a #[my_macro(skip)] annotation. If I implemented it slightly differently, I would also be transforming field types based on annotations on the fields, e.g.:

#[my_io]
struct S {
    #[my_io(in)]
    a: u32,
    #[my_io(out)]
    b: i16,
}

would covert to something like

struct S {
    a: Input<u32>,
    b: Output<i16>,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants