-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Visitor for stable rust #743
Conversation
@kdy1 I tried impl Visit for LintContext {
fn visit_module(&self, module: &Module, parent: &dyn Node) {
assert!(self.scope_stack.is_empty());
let module_node = Box::new(AstNode::Module(module.clone()));
let current_scope = self.get_current_scope();
let module_scope = Rc::new(RefCell::new(Scope::new(
module_node.clone(),
ScopeKind::Module,
Some(current_scope.clone()),
)));
// Entering module scope
self.scope_stack.push(module_scope);
// Call default implementation and walk children
// NOTE: this doesn't work
Visit::visit_module(self, module, parent);
// Exiting module scope
self.scope_stack.pop();
}
} How do I go about calling default implementation of |
@bartlomieju It can be solved by extracting default behavior as a function. It would be like pub trait Visit {
fn visit_module(&mut self, n: &Module, parent: &dyn Node) {
visit_module(self, n, parent)
}
}
pub fn visit_module<V>(v: &mut V, module: &Module, parent: &Node) {
// default implementation lives here
} I'll do it tomorrow (well, actually it's today for me as it's over 12pm). |
@kdy1 awesome, thank you! |
@bartlomieju I did it. Can you check it, please? |
Co-Authored-By: Bartek Iwańczuk <[email protected]>
@kdy1 any chance you could release it today? |
@bartlomieju I published it. |
@kdy1 kudos! |
I've implemented a Visitor for stable rustc.
The implementation is naive, but it works.
Generated code looks like
where
Node
is declared ascc @ry @bartlomieju