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

code cleanup: if visit::walk_foo(a, b, c) discards b, then b should not be in its API. #14134

Closed
pnkfelix opened this issue May 12, 2014 · 2 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@pnkfelix
Copy link
Member

The pattern for our syntax::visit module is that each visit method has a default implementation that just walks the substructure of that node in the AST.

What I often do when implementing a visitor is cut-and-paste the trait definition (with its default methods) into my new visitor and then consider each method to determine whether it should (1.) do extra-work, and/or (2.) stop the traversal, or (3.) just use the default impl.

When I see something like:

fn visit_struct_def(&mut self, s: &StructDef, i: Ident, g: &Generics, n: NodeId, e: E) {
    walk_struct_def(self, s, i, g, n, e)
}

I might assume: "Ah, the walk routine is already going to look at i and g, so if I need to look at those in my own code, then I can just inherit the visitor's default method."

The problem with that assumption is this:

pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V,
                                                struct_definition: &StructDef,
                                                _: Ident,
                                                _: &Generics,
                                                _: NodeId,
                                                env: E) {
   ...
}

My proposal solution: Any fn walk_foo in visit.rs should not have any parameters that are ignored.

@pnkfelix
Copy link
Member Author

(on the other hand, an argument for going with the existing pattern is that it might make it easier to macro-generate the function signatures and calls semi-automatically. The problem with that argument is that not all of the walk_foo pass all of variant's state; only some of them do. I suspect we'd be better off following the proposal I gave in the description above.)

@pongad
Copy link
Contributor

pongad commented May 14, 2014

I'll work on this.

@bors bors closed this as completed in 96bcadc May 14, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
feat: Add clippy configuration section to the manual and update some old keys

Closes rust-lang#14132

I don't think this is supposed to be under `Diagnostics`, but it does make sense in a way 🤷 (it's probably where someone might look).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants