diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2025-06-01 02:38:24 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2025-06-01 02:38:24 +0000 |
| commit | c33b08552b7741828488ada70afdce12122fd97b (patch) | |
| tree | 71f4ec2a1d18ba4702bf7777f7a8209796a9552f /compiler/rustc_lint/src/early.rs | |
| parent | 738c08b63c4f9e3ebdaec5eece7b6fbc354f6467 (diff) | |
| download | rust-c33b08552b7741828488ada70afdce12122fd97b.tar.gz rust-c33b08552b7741828488ada70afdce12122fd97b.zip | |
Add `visit_id` to ast `Visitor`
This helps with efforts to deduplicate the `MutVisitor` and the `Visitor` code. All users of `Visitor`'s methods that have extra `NodeId` as parameters really just want to visit the id on its own. Also includes some methods deduplicated and cleaned up as a result of this change.
Diffstat (limited to 'compiler/rustc_lint/src/early.rs')
| -rw-r--r-- | compiler/rustc_lint/src/early.rs | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 0c62c14af63..4978f293ab7 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -74,8 +74,8 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> { impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> for EarlyContextAndPass<'ecx, 'tcx, T> { - fn visit_coroutine_kind(&mut self, coroutine_kind: &'ast ast::CoroutineKind) -> Self::Result { - self.check_id(coroutine_kind.closure_id()); + fn visit_id(&mut self, id: rustc_ast::NodeId) { + self.check_id(id); } fn visit_param(&mut self, param: &'ast ast::Param) { @@ -101,7 +101,6 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> fn visit_pat(&mut self, p: &'ast ast::Pat) { lint_callback!(self, check_pat, p); - self.check_id(p.id); ast_visit::walk_pat(self, p); lint_callback!(self, check_pat_post, p); } @@ -112,11 +111,6 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> }); } - fn visit_anon_const(&mut self, c: &'ast ast::AnonConst) { - self.check_id(c.id); - ast_visit::walk_anon_const(self, c); - } - fn visit_expr(&mut self, e: &'ast ast::Expr) { self.with_lint_attrs(e.id, &e.attrs, |cx| { lint_callback!(cx, check_expr, e); @@ -157,13 +151,6 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> ast_visit::walk_fn(self, fk); } - fn visit_variant_data(&mut self, s: &'ast ast::VariantData) { - if let Some(ctor_node_id) = s.ctor_node_id() { - self.check_id(ctor_node_id); - } - ast_visit::walk_struct_def(self, s); - } - fn visit_field_def(&mut self, s: &'ast ast::FieldDef) { self.with_lint_attrs(s.id, &s.attrs, |cx| { ast_visit::walk_field_def(cx, s); @@ -179,7 +166,6 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> fn visit_ty(&mut self, t: &'ast ast::Ty) { lint_callback!(self, check_ty, t); - self.check_id(t.id); ast_visit::walk_ty(self, t); } @@ -196,7 +182,6 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> fn visit_block(&mut self, b: &'ast ast::Block) { lint_callback!(self, check_block, b); - self.check_id(b.id); ast_visit::walk_block(self, b); } @@ -257,29 +242,13 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> }); } - fn visit_lifetime(&mut self, lt: &'ast ast::Lifetime, _: ast_visit::LifetimeCtxt) { - self.check_id(lt.id); - ast_visit::walk_lifetime(self, lt); - } - - fn visit_path(&mut self, p: &'ast ast::Path, id: ast::NodeId) { - self.check_id(id); - ast_visit::walk_path(self, p); - } - - fn visit_path_segment(&mut self, s: &'ast ast::PathSegment) { - self.check_id(s.id); - ast_visit::walk_path_segment(self, s); - } - fn visit_attribute(&mut self, attr: &'ast ast::Attribute) { lint_callback!(self, check_attribute, attr); ast_visit::walk_attribute(self, attr); } - fn visit_macro_def(&mut self, mac: &'ast ast::MacroDef, id: ast::NodeId) { + fn visit_macro_def(&mut self, mac: &'ast ast::MacroDef) { lint_callback!(self, check_mac_def, mac); - self.check_id(id); } fn visit_mac_call(&mut self, mac: &'ast ast::MacCall) { |
